Android版式优先?

洪洪

我学习了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>
Himanshu Dudhat

否没有任何优先级。

您已将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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Android版式设计:平板电脑优先或手机优先

来自分类Dev

Android版式上下

来自分类Dev

Android版式TextView

来自分类Dev

日历控制的Android版式

来自分类Dev

Android的广告版式问题

来自分类Dev

Android版式无法正常工作

来自分类Dev

Android版式:运行第二个版式传递

来自分类Dev

Android版式-何时使用app:vs android :?

来自分类Dev

Android View填充版式的中心区域

来自分类Dev

在Android版式中扭曲了ProgressBar微调器

来自分类Dev

Android版式:父宽度的一半

来自分类Dev

Android版式对齐方式在Landscape中混乱了

来自分类Dev

Android:无法在版式中填充EditText

来自分类Dev

无法使用Android版式充气机?

来自分类Dev

Android版式-适用于所有屏幕尺寸的一种版式吗?

来自分类Dev

Android版式中的Kitkat和Post-kitkat版本中的不同版式

来自分类Dev

Android版式-适用于所有屏幕尺寸的一种版式吗?

来自分类Dev

Android:如何将版式“插入”到另一个版式?

来自分类Dev

Android MultiSelectListPreference的优先顺序

来自分类Dev

Android:定位优先

来自分类Dev

如何在Android版式的顶部固定应用栏和Edittext

来自分类Dev

如何在Android版式中创建TAB VIEW

来自分类Dev

Eclipse Content Assist对于Android版式无法正常工作

来自分类Dev

按屏幕尺寸而非dpi划分的Android版式

来自分类Dev

Android两版式进行一项活动

来自分类Dev

Android版式屏幕尺寸冲突(正常值/大值)

来自分类Dev

如何在Android版式中显示HTML内容?

来自分类Dev

如何在Android版式中创建TAB VIEW

来自分类Dev

Android两版式进行一项活动