Java 为什么不是';是否显示正确的布局?
我正在努力学习布局。Java 为什么不是';是否显示正确的布局?,java,android,android-linearlayout,android-relativelayout,Java,Android,Android Linearlayout,Android Relativelayout,我正在努力学习布局。 我正在尝试的布局是: ___________________________________________________ | | | VIEW PAGER | |___________________________________________________| |
我正在尝试的布局是:
___________________________________________________
| |
| VIEW PAGER |
|___________________________________________________|
| | |
| TEXT | TEXT |
|_________________________|_________________________|
| | | | |
| | TEXT | | TEXT |
| TEXT |____________| TEXT |____________|
| | | | |
| | TEXT | | TEXT |
|____________|____________|____________|____________|
有人能帮我理解为什么viewpage下的布局的正确部分(注释下一个信息单元格后的部分)没有显示,以及如何修复它吗
<?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"
>
<android.support.v4.view.ViewPager
android:id="@+id/friend_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
/>
<LinearLayout
android:layout_below="@id/friend_viewpager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Previous Info"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1"
>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:editable="false"
android:gravity="center"
android:text="Bla"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bla Bla"
android:gravity="center"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bla Bla Bla"
android:gravity="center"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<!-- NEXT -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Next Info"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1"
>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Bla"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bla Bla"
android:gravity="center"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bla Bla Bla"
android:gravity="center"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
你说他们需要占用相等的空间。 尝试使用
布局重量=“0.5”
layout_width=“0dp”
用于需要具有相同水平宽度的相同级别子布局
添加到子项下面是问题的简化版本。它与外部
RelativeLayout
或TextView
s无关。这就是我所说的解决这个问题的方法。我已经修剪了脂肪,但仍然看到了问题所在
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffff0000" />
<!-- NEXT -->
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ff00ff00" />
</LinearLayout>
您使用的权重不正确,此示例适用于:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="2">
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:background="#ffff0000" />
<!-- NEXT -->
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:background="#ff00ff00" />
</LinearLayout>
变成:
这是显示问题的最简单示例?如果你做出决定,你可以回答你自己的问题。韦斯顿:我不知道什么部分是不相关的。我确实注意到,如果我将左侧单元格的
layout\u width
更改为wrap\u content
,那么两个布局都会显示出来,但我希望它们占用相同的空间“我不知道什么部分是不相关的”找出答案!你读过链接了吗?@weston:我更新了OP,以显示我试图将这些添加到父母或孩子身上的内容?这很奇怪。在我读过的教程中,我不记得为weight\u sum设置了一个值。事实上,这是我第一次看到这个属性。从技术上讲,如果你在每个孩子身上设置权重,这不是必需的。这个例子在没有它的情况下可以工作。但是,如果要从一个视图中省略布局权重
,或者甚至没有第二个视图并且需要间隙,则需要求和。听起来你所做的教程在这方面还不够完整。