想用两个LinearLayouts为我的应用程序分割一个屏幕。我应该使用哪些参数来精确分割两个相等的部分 - 第一个是LinearLayout,第二个是正下方。如何用两个相等的LinearLayout分割屏幕?
回答
使用重量参数,大致的布局将类似于这样:
<LinearLayout android:orientation="horizontal"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<LinearLayout
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="0dp"/>
<LinearLayout
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="0dp"/>
</LinearLayout>
您拼写了第3个LinearLayout错误。 – Doomsknight 2012-09-05 13:16:08
@Doomsknight thx,修正! – 2012-09-09 07:53:58
查看本教程中有关使用layout_weight属性的信息http://www.chess-ix.com/2012/01/17/the-use-of-layout_weight-with-android-layouts/ – 2012-09-24 18:19:43
只是把它在那里:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000"
android:weightSum="4"
android:padding="5dp"> <!-- to show what the parent is -->
<LinearLayout
android:background="#0000FF"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="2" />
<LinearLayout
android:background="#00FF00"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1" />
</LinearLayout>
我后4-5年,但这样做的最佳实践回答这个问题这是下面
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="@+id/secondView"
android:orientation="vertical"></LinearLayout>
<View
android:id="@+id/secondView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_centerHorizontal="true" />
<LinearLayout
android:id="@+id/thirdLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/secondView"
android:orientation="vertical"></LinearLayout>
</RelativeLayout>
这是正确的做法是使用layout_的对于UI操作来说,重量总是很重的。 使用LinearLayout同等地分割布局不是好的做法
- 1. 使用LinearLayout分割屏幕的问题
- 2. 如何分割三个div的屏幕
- 3. 如何用两个按钮分割屏幕?
- 4. 将主页屏幕分割为两个屏幕
- 5. 将Android屏幕分成两半等分
- 6. Cocos2d上的分割屏幕
- 7. libgdx如何将屏幕分割4份
- 8. 如何在iphone中分割屏幕?
- 9. 如何在屏幕上水平分割屏幕
- 10. 如何在两个相等的部分
- 11. 分割屏幕一半CSS
- 12. SDL图像分割屏幕
- 13. Javascript分割屏幕视图
- 14. 如何在多于一个部分分割屏幕
- 15. 如何将C++控制台屏幕分割成多个部分?
- 16. 分割屏幕在两个(水平或垂直)
- 17. 将屏幕分割为两个视图控制器SpritKit + Swift
- 18. 五等分划分屏幕
- 19. 大于屏幕的LinearLayout
- 20. 保持在的LinearLayout屏幕
- 21. 用GTK +/gtkmm Grid分割屏幕
- 22. 分成两个部分屏幕
- 23. 将屏幕分成与溢出相等的部分
- 24. 如何将一个NSArray分成两个相等的部分?
- 25. 分割整数分成相等的块
- 26. 如何将gridview拆分成相等的部分来填充屏幕
- 27. 如何使用LinearLayout将两个图像放在相反两端?
- 28. LinearLayout被推下屏幕
- 29. fill_parent不填满整个屏幕在LinearLayout
- 30. Xcode的分割屏幕分为4个巨人按钮
对每个布局使用权重= 0.5 – Sephy 2010-08-06 15:10:33
两个布局的权重应该是“相同的”,不一定是分数 – Siddharth 2013-07-05 03:24:58