我想要一個按鈕始終出現在固定的位置,在UI的頁腳中? (總是,如果它有或沒有的組件)如何在UI底部的固定位置設置按鈕?
回答
請把你的主要佈局在一個相對佈局。將其高度和寬度設置爲填充父級,並將其重力設置爲底部,並將所需的任何文本視圖或任何按鈕放入其中。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Bottom Gravity" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Without Gravity" />
</LinearLayout>
</FrameLayout>
完美答案。作品。但應該使用「match_parent」而不是「fill_parent」 – rjdthegreat
這對我來說也很好 –
設置android:layout_gravity="bottom"
。希望這可以幫助。
這取決於您使用的佈局。
在一個RelativeLayout的有
android:layout_alignParentBottom="true"
在一個LinearLayout中,將其放置在底部,並確保設置元素layout_weight正常。
此外,檢查屬性
android:layout_gravity
,並注意到它的不同比
android:gravity
我確認你的答案,他應該使用一個relativeLayout來修復底部的按鈕'android:layout_alignParentBottom = 「true」,我想補充一點,如果他想讓自己的按鈕保持在前面,在他的代碼中,他可以調用方法:'btn.bringToFront()' – Houcine
,如果任何一個有兩個按鈕,你可以做這一點,獸人我
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom" >
<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_yes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:text="Valider"/>
<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_no"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:text="Annuler"/>
</LinearLayout>
</RelativeLayout>`
- 1. 如何設置android底部導航欄位置固定在android
- 2. CSS - 位置固定,底部
- 3. 如何在方向更改後設置按鈕位置固定
- 4. 固定底部全寬度位置按鈕反應原生
- 5. 按鈕固定位置
- 6. 固定按鈕位置
- 7. 固定(底部)位置的中心DIV
- 8. 將按鈕放在固定的位置?
- 9. 我想設置div底部的按鈕位置
- 10. iPhone&iPad位置:固定底部問題
- 11. CSS位置固定底部頁腳
- 12. 語義UI:如何在列的底部放置一個按鈕?
- 13. 離子:從底部的位置按鈕
- 14. 在UITableView底部的固定按鈕
- 15. 固定在屏幕底部的按鈕
- 16. 如何在JFrame的任何位置設置按鈕的位置
- 17. 如何在HTML中創建底部固定位置菜單?
- 18. IE8底部:0位置:絕對行爲像位置:固定
- 19. 禁用固定的按鈕位置
- 20. 的UIScrollView保持按鈕固定位置
- 21. 如何設置j按鈕的位置?
- 22. 固定在圖像的頂部位置FB Like按鈕(響應)
- 23. 如果啓用滾動,如何在底部設置按鈕?
- 24. 設置位置固定
- 25. 設置按鈕的位置
- 26. 自舉固定位置按鈕
- 27. 如何設置按鈕位置?
- 28. 如何設置按鈕位置
- 29. Facebook like按鈕出現在固定位置元素頂部
- 30. 如何在scrollView的底部設置按鈕,使按鈕被軟鍵盤覆蓋
發表您的XML這裏 – ingsaurabh
來吧,這裏貼上XML(上gist.github.com如果過大),請 –
相同http://stackoverflow.com/questions/14779688/和http://stackoverflow.com/questions/2386866 –