【发布时间】:2014-10-04 01:08:34
【问题描述】:
我学习了 Android XML,但在布局方面遇到了问题。 可以看到,我声明了2个线性布局和1个相对布局,所以顺序是Linear (1) - Relative (2) - Linear (3) 但是,当我运行它时,显示显示线性 (1) - 线性 (3) - 相对 (2)。
所以,我想知道布局中是否有优先级或规则:)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffff0000"
>
<Button
android:id="@+id/backBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Linear_Layout1 (1)"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff000000"
>
<TextView
android:id="@+id/text01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Relative_layout1 (2)"
android:textColor="#ff0000ff"
android:textSize="19dp"
/>
<TextView
android:id="@+id/text02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mosquito"
android:textColor="#ff00ff00"
android:textSize="15dp"
android:background="#ffff0000"
android:layout_centerInParent="true"
android:layout_toRightOf="@id/text01"
/>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"
android:background="#fff0f0f0"
>
<TextView
android:id="@+id/text03"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Linear_layout2 (3)"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
【问题讨论】:
-
这可能是因为
RelativeLayout的高度为match_parent,将其更改为wrap_content并检查。而你的LinearLayout(2)在RelativeLayout里面。试着把它放在外面。 -
为
LinearLayout中的第三个LinearLayout定义以下属性..
标签: java android xml android-layout