我有以下 xml,它应该类似于 the following
Activity 显示大部分正常,但我无法将两个向下按钮固定到屏幕底部而不弄乱顶部 View 。
我尝试将 FrameLayout
与两个 RelativeLayouts
、alignment_bottom、组件之间权重为 1 的空 View 一起使用,甚至仍然无法实现我的目标。非常感谢任何帮助,在此先感谢您。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView android:layout_width="match_parent" android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/RelativeLayout1">
<ImageView
android:id="@+id/group_info_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:adjustViewBounds="true"
android:layout_alignParentTop="true"
/>
<TextView
android:id="@+id/description_text"
android:layout_below="@id/group_info_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/mainColor"
android:textSize="20sp"
android:text="@string/descripcion"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:fontFamily="sans-serif"
/>
<TextView
android:layout_below="@id/description_text"
android:gravity="start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/group_info_description"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:layout_marginStart="10dp"
android:textSize="15sp"/>
<TextView
android:layout_below="@id/group_info_description"
android:scrollbars="vertical"
android:gravity="center"
android:textColor="@android:color/black"
android:layout_marginTop="10dp"
android:layout_marginStart="5dp"
android:layout_marginBottom="2dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/group_info_user_number"
android:textSize="15sp"
/>
<es.tretornesp.clickerchat.NonScrollableListView
android:layout_below="@id/group_info_user_number"
android:id="@+id/group_info_user_list"
android:layout_height="match_parent"
android:divider="@drawable/list_divider"
android:dividerHeight="1px"
android:layout_width="match_parent"/>
</RelativeLayout>
</ScrollView>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/delete_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/borrar_grupo"
android:background="@color/mainColor" />
<View
android:id="@+id/divisor"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/grey"/>
<Button
android:id="@+id/exit_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:text="@string/salir"
android:background="@color/mainColor"
/>
</LinearLayout>
</LinearLayout>
最佳答案
如下更改布局文件,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/exit_group">
<RelativeLayout
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/group_info_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:scaleType="fitStart" />
<TextView
android:id="@+id/description_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/group_info_image"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:fontFamily="sans-serif"
android:text="@string/descripcion"
android:textColor="@color/mainColor"
android:textSize="20sp" />
<TextView
android:id="@+id/group_info_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/description_text"
android:layout_marginBottom="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:gravity="start"
android:textSize="15sp" />
<TextView
android:id="@+id/group_info_user_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/group_info_description"
android:layout_marginBottom="2dp"
android:layout_marginStart="5dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:scrollbars="vertical"
android:textColor="@android:color/black"
android:textSize="15sp" />
<es.tretornesp.clickerchat.NonScrollableListView
android:id="@+id/group_info_user_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/group_info_user_number"
android:divider="@drawable/list_divider"
android:dividerHeight="1px" />
<Button
android:id="@+id/delete_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/group_info_user_list"
android:background="@color/mainColor"
android:text="@string/borrar_grupo" />
<View
android:id="@+id/divisor"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/delete_group"
android:background="@color/grey" />
</RelativeLayout>
</ScrollView>
<Button
android:id="@+id/exit_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/mainColor"
android:text="@string/salir"
android:textColor="@android:color/white" />
</RelativeLayout>
关于底部固定按钮的Android布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52137906/