在我的布局中,有四个部分分别是标题,可编辑控件,列表和一组按钮.我想将按钮保持在屏幕下方.我在布局上做了太多更改以强制按钮到底.但什么都没发生.请提供说明,以满足我的需求.我也在发布布局
<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <!-- heading for basic settings --> <TextView android:id="@+id/setup_macroheading" style="@style/txtheading" /> <View android:layout_width="fill_parent" android:layout_height="20dp"/> <!-- macro name --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="20dp" android:paddingRight="20dp" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="left|center_vertical" android:layout_weight="1" android:textColor="@color/white" android:text="Macro Name"/> <EditText android:id="@+id/setup_macroname" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_weight="1" android:maxLength="12" android:inputType="textCapCharacters" android:singleLine="true"/> </LinearLayout> <View android:layout_width="fill_parent" android:layout_height="20dp"/> <ListView android:id="@+id/lvMacroList" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <!-- Save & Cancel button --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="20dp" android:paddingRight="20dp" android:layout_gravity="bottom" android:orientation="horizontal"> <Button android:id="@+id/setup_macroSavebtn" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="left" android:layout_weight="1" android:onClick="onSaveButtonClick" android:text="Save"/> <Button android:id="@+id/setup_macroCancelbtn" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_weight="1" android:onClick="onCancelButtonClick" android:text="Cancel"/> </LinearLayout> </LinearLayout> </ScrollView>
解决方法
将包含按钮的LinearLayout的Parent设置为relative,并将包含两个按钮的线性布局的属性设置为android:layout_alignParentBottom =“true”.您还可以将“线性布局”的重力设置为“底部”.
试试这个:
<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <!-- heading for basic settings --> <TextView android:id="@+id/setup_macroheading" style="@style/txtheading" /> <View android:layout_width="fill_parent" android:layout_height="20dp"/> <!-- macro name --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="20dp" android:paddingRight="20dp" android:orientation="horizontal"> <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="left|center_vertical" android:layout_weight="1" android:textColor="@color/white" android:text="Macro Name"/> <EditText android:id="@+id/setup_macroname" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_weight="1" android:maxLength="12" android:inputType="textCapCharacters" android:singleLine="true"/> </LinearLayout> <View android:layout_width="fill_parent" android:layout_height="20dp"/> <ListView android:id="@+id/lvMacroList" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> <!-- Save & Cancel button --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_gravity="bottom" android:orientation="horizontal" android:paddingLeft="20dp" android:paddingRight="20dp" > <Button android:id="@+id/setup_macroSavebtn" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="left" android:layout_weight="1" android:onClick="onSaveButtonClick" android:text="Save"/> <Button android:id="@+id/setup_macroCancelbtn" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_weight="1" android:onClick="onCancelButtonClick" android:text="Cancel"/> </LinearLayout> </RelativeLayout>
原文地址:https://www.jb51.cc/android/317171.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。