java - Android layout_weight iframe 和滚动
问题描述
抱歉,我的英语很差,我在 android studio 上遇到了设计问题。我使用了多个设备(从版本 8 到 10)并且工作正常,并且一个设备(版本 6)具有不同的输出(您可以在下面查看我的屏幕)错误的显示单击此处 良好的显示单击此处 不幸的是我不知道为什么会出错,这可能是 layout_weight 的问题,在我的代码中,我使用 Frame 布局在不同的视图之间切换,看起来 Framelayout 不需要任何高度(我希望它占用可用空间)谢谢提前
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/choose_model"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0">
<Spinner
android:id="@+id/select_your_model"
android:layout_width="43dp"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/text_model_title"
android:layout_alignParentEnd="true" />
<TextView
android:id="@+id/text_model_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="5dp"
android:layout_marginTop="20dp"
android:text="@string/choose_mod"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/Spinner_model_preference_text"
android:layout_width="160dp"
android:layout_height="26dp"
android:layout_alignTop="@+id/select_your_model"
android:layout_alignParentEnd="true"
android:layout_marginEnd="45dp"
android:gravity="center"
android:textColor="@android:color/darker_gray"
android:textSize="16sp"
android:textStyle="bold" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="15dp"
android:layout_weight="1"
android:background="#FAFAFA">
<FrameLayout
android:id="@+id/Frame_layout_preferences_setting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_weight="0">
<Button
android:id="@+id/save_user_preferences"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="@string/save" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view_preferences_model"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<View
android:id="@+id/divider2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="@+id/recycler_view_preferences_model"
android:layout_alignParentStart="true"
android:background="?android:attr/listDivider" />
</RelativeLayout></LinearLayout>
解决方案
您有问题,因为您在片段中有一个 FrameLayout。我推荐下一个
如果你只想有一个视图并且它有不同的内容,你可以有一个活动
<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0"> <Spinner android:id="@+id/select_your_model" android:layout_width="43dp" android:layout_height="wrap_content" android:layout_alignTop="@+id/text_model_title" android:layout_alignParentEnd="true" /> <TextView android:id="@+id/text_model_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:layout_marginStart="5dp" android:layout_marginTop="20dp" android:text="@string/choose_mod" android:textSize="20sp" android:textStyle="bold" /> <TextView android:id="@+id/Spinner_model_preference_text" android:layout_width="160dp" android:layout_height="26dp" android:layout_alignTop="@+id/select_your_model" android:layout_alignParentEnd="true" android:layout_marginEnd="45dp" android:gravity="center" android:textColor="@android:color/darker_gray" android:textSize="16sp" android:textStyle="bold" /> </RelativeLayout> <ScrollView android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginTop="15dp" android:layout_weight="1" android:background="#FAFAFA"> <FrameLayout android:id="@+id/Frame_layout_preferences_setting" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" /> </ScrollView> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:layout_weight="0"> <Button android:id="@+id/save_user_preferences" android:layout_width="wrap_content" android:layout_height="40dp" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:gravity="center" android:text="@string/save" /> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="0.2"> <android.support.v7.widget.RecyclerView android:id="@+id/recycler_view_preferences_model" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" /> <View android:id="@+id/divider2" android:layout_width="match_parent" android:layout_height="1dp" android:layout_above="@+id/recycler_view_preferences_model" android:layout_alignParentStart="true" android:background="?android:attr/listDivider" /> </RelativeLayout></LinearLayout>
用图像视图替换 FrameLayout
如果你想有片段。我推荐下一个
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
在活动中调用片段
getSupportFragmentManager().beginTransaction() .replace(R.id.main_container, fragment, fragment.getClass().getSimpleName()).addToBackStack(null).commit();
推荐阅读
- angular - 在编辑模式下打开表单时,数据绑定不适用于多个表单控件
- c++ - 计算蹦床钩的 JMP 指令地址
- python - Pythonic方法来获取列表中每个元素与其他元素的减法列表?
- python - MLFlow SparkTrials maxNumConcurrentTasks([]) 不存在
- mysql - SQL 仅获取重复行中的较早日期
- python - 在 Python/Tensorflow 中:如何将 2D 数组的字符串表示形式从文本文件转换为 TF 可以使用的东西
- javascript - Jest 精确对象匹配
- mysql - 查询 SQL Group By 不根据第一个元素进行分组
- mysql - CTE DELETE 不可更新
- java - 关闭应用程序后,哈希图中的数据不保存