![](/img/trans.png)
[英]Android: How to align button to the bottom and above the keyboard when it is up?
[英]How to place a button at a position little above the bottom in android
我需要在屏幕底部放置一个按钮,在其下方留出一些空间。 换句话说,我将这两个属性用于我的按钮 -
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"
但是当我使用alignParentBottom并且按钮仅在底部粘贴时,margin属性不起作用。 请告诉我如何将它放在底部稍上方。
这是xml
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:background="@drawable/board"
android:layout_marginLeft="10dp"
android:layout_marginRight="60dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="10dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Type of Lesion"
android:textColor="#8B0A50"
android:layout_marginTop="40dp"
android:id="@+id/disease_listheader_textview"
android:drawableBottom="@drawable/underline"/>
<ListView
android:id="@+id/disease_listview"
android:layout_below="@id/disease_listheader_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="@drawable/divider"
android:layout_marginLeft="40dp"
android:layout_marginBottom="50dp"
android:cacheColorHint="#00000000"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/disease_search_button"
android:layout_centerHorizontal="true"
android:background="@drawable/disease_search_btn"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"/>
</RelativeLayout>
只需将相对布局高度属性值更改为fillparent就好了
<RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" .................../>
希望这能帮助你
你能试试吗?
将Button标签替换为下面提到的标签。 我试图将按钮包裹在另一个虚拟布局中
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_alignParentBottom="true" android:paddingBottom="20dp"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/disease_search_button" android:background="@drawable/disease_search_btn" android:layout_marginBottom="20dp"/> </LinearLayout>
这可以按照您想要的方式运行
<RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="match_parent" android:layout_height="fill_parent">
<Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="20dip"></Button>
</RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.