我想用3个视图水平填充整个屏幕。我希望他们都是相同的大小。如果我用dp手动输入宽度的值,其中一个比另一个要大,或者在更换设备时它不会填满大的屏幕。什么是正确的做法呢? 用3个视图水平填充整个屏幕?
0
A
回答
2
您可以使用具有“fill_parent”宽度属性的父布局,然后为每个视图给出layout_weight =“1”。
试试这个。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<Button android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text"
android:layout_weight="1"/>
<Button android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text"
android:layout_weight="1"/>
<Button android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text"
android:layout_weight="1"/>
</LinearLayout>
2
我想评论,但我没有足够的代表。所以我发布这个答案。你是用水平的LinearLayout
来包装这三个?如果是,您是否尝试过使用属性android:layout_weight
?如果还没有,请在布局XML中为所有这些视图设置android:layout_weight="1"
。这应该平等地看待这些观点。但是,如果您可以发布您的XML代码,那将会更有帮助。
+0
现在你可以发表评论.. :) :)你给权利ans但适当的必要的解释哪个人发布问题,他们不知道权重,所以如果你写这个,然后他们不会理解。因为如果他们知道体重,那么他不会在这里发表问题..对。错过:) –
+0
@VishalHalani谢谢。 :)下次我会记住这一点。 –
9
试试这个代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Test" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Test" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Test" />
</LinearLayout>
</RelativeLayout>
2
你可以像这样,我只是将按钮你写其他componants也
<LinearLayout xmlns:android="http://schemas.android.com/apk/re/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Test" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Test" />
<Button
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Test" />
</LinearLayout>
相关问题
- 1. 图案填充整个屏幕
- 2. Android水平回收视图在景观上填充屏幕
- 3. BlackBerry Image字段水平填充屏幕
- 4. 图库视图不填充整个屏幕获得创建
- 5. 使用div填充整个屏幕
- 6. 用TextInputLayout填充整个屏幕区域
- 7. 屏幕上有3个选项的水平滚动视图
- 8. Eclipse自动填充视图变宽,并阻止整个屏幕
- 9. 列表视图,而不是填充整个屏幕
- 10. 制作部分填充整个屏幕
- 11. 内联svg填充整个屏幕
- 12. 回需要填充整个屏幕
- 13. 响应DIV填充整个屏幕
- 14. 使按钮变窄而不是水平填满整个屏幕
- 15. 强制视频以填充整个可视屏幕
- 16. UICollectionViewCell不填充整个屏幕中夫特3
- 17. 有两个视图的ScrollView,第一视图填充屏幕
- 18. 以多种屏幕分辨率填充整个屏幕,密度
- 19. 填充多个DIV屏幕
- 20. UITable视图填充整个视图
- 21. 水平填充不能在手机屏幕上使用css flexbox
- 22. android:fill_parent子视图填充屏幕
- 23. UINavigationController视图不会填充屏幕
- 24. pygame.display.set_mode填满整个屏幕
- 25. AVCaptureSession和预览图层不会填充整个屏幕
- 26. 填充整个屏幕与背景图像!
- 27. Rstudio中的Rpresentation - 使图像填充整个屏幕
- 28. Android:拉伸位图以填充整个屏幕
- 29. 有两个视图水平填充容器查看器吗?
- 30. 调整EditText(或一般视图)以填充屏幕
什么,因为 – raj
ü试图建立一个相对布局,并在此创建线性布局与水平横向也给予重量1线性布局 – raj
每个按钮,并且不要忘记给父线性布局权重总和= 3。 – Praneeth