我学习了Android XML,但是遇到了布局问题。如您所见,我声明了2个线性布局和1个相对布局,因此顺序为线性(1)-相对(2)-线性(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>
否没有任何优先级。
您已将android:layout_centerInParent =“ true”设置为text01,并且相对布局的任何子视图均未对齐。
当您未为相对布局的子视图分配任何对齐方式时,该对齐方式将发生重叠(并从下到上添加到堆栈中)
签出更新的视图,该视图从上到下以相对布局添加视图
<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: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:layout_below="@+id/text01"
android:layout_toRightOf="@id/text01"
android:background="#ffff0000"
android:text="Mosquito"
android:textColor="#ff00ff00"
android:textSize="15dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/text02"
android:background="#fff0f0f0"
android:orientation="vertical" >
<TextView
android:id="@+id/text03"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Linear_layout2 (3)" />
</LinearLayout>
</RelativeLayout>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句