我想要一个按钮始终出现在固定的位置,在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 –