我使用以下XML绘制带有标题、子标题、图像和按钮的布局。图像占用了所有剩余的空间,但在最后,我将其设置为visibility = View.GONE,并且我的按钮没有对齐到底部。我做错了什么?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:baselineAligned="false">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/kasel"
android:id="@+id/txtChokeNext"
android:textSize="20sp"
android:gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_gravity="top"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/kaselDesc"
android:id="@+id/txtChokeNextDesc"
android:gravity="center"
android:layout_marginTop="10dp"
android:textStyle="bold"
android:layout_gravity="top"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/imgChokeDesc"
android:src="@drawable/kasel"
android:adjustViewBounds="true"
android:baselineAlignBottom="false"
android:cropToPadding="false"
android:layout_weight="1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/firstAidNext"
android:id="@+id/buttonChokeNext"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingTop="20dp"
android:paddingRight="10dp"
android:paddingBottom="20dp"
android:layout_gravity="bottom"
/>
</LinearLayout>前谢
发布于 2015-02-04 07:48:15
您可以将布局更改为RelativeLayout,并将此参数设置为Button:
android:layout_alignParentBottom="true"您还应该在子标头和图像中添加android:layout_below="...",以便一个接一个地放置它们(替换.使用应该在您正在编辑的元素之上的元素的id )
发布于 2015-02-04 07:45:28
解决你的问题
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/kasel"
android:id="@+id/txtChokeNext"
android:textSize="20sp"
android:gravity="center_horizontal"
android:layout_marginTop="10dp"
android:layout_gravity="top" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/kaselDesc"
android:id="@+id/txtChokeNextDesc"
android:gravity="center"
android:layout_marginTop="10dp"
android:textStyle="bold"
android:layout_gravity="top" />
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/imgChokeDesc"
android:src="@drawable/kasel"
android:adjustViewBounds="true"
android:baselineAlignBottom="false"
android:cropToPadding="false"
android:layout_weight="1" />
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/firstAidNext"
android:id="@+id/buttonChokeNext"
android:layout_marginTop="10dp"
android:paddingLeft="10dp"
android:paddingTop="20dp"
android:paddingRight="10dp"
android:paddingBottom="20dp"
android:layout_gravity="bottom" />
</LinearLayout>https://stackoverflow.com/questions/28315950
复制相似问题