![](/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.