java - Android静态片段 - 应用程序崩溃问题
问题描述
我是一名 android 初学者,刚刚学习 android 静态片段概念,但在运行我的代码后出现应用程序崩溃问题。以下是详细信息:
MainActivity.java
package com.example.lalendrakumar.fragmentdemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:weightSum="2">
<fragment
android:id="@+id/fragment1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<fragment
android:id="@+id/fragment2"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
所以任何人都可以解决我的问题。
解决方案
我假设您希望这两个片段填充页面。“fill_parent”现在已被“match_parent”取代。但是,如果您使用它,理论上,这两个片段将彼此重叠。
要在屏幕上拆分它们,每个都必须调整到零高度。这是每个片段的尺寸应该如何读取
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
推荐阅读
- android - 反应原生 | @react-native-community_picker 在 android 上未解决
- python - 命令提示符: pip install mod_wsgi
- regex - 使用 java 脚本在字符串 `,"'/\{}[]() 中,这个字符表示我需要显示验证消息。否则我需要允许下一个过程
- python - Python如何将移动操作还原到文件中
- linux - 如何在多阶段 Docker 文件中将所有工件从源复制到目标
- python - *pool2D 和 *pooling2D 之间的 TensorFlow 差异
- javascript - React Native:让 ScrollView 的每个子项全高
- javascript - 如何将“活动”类添加到 javascript 中单击的导航链接?
- java - Remove last digit in a string in Java only if it is just one digit present
- node.js - 我将如何更改 json 文件中字符串中的值?