Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 对齐到相对布局的右侧似乎不起作用_Android_Android Relativelayout - Fatal编程技术网

Android 对齐到相对布局的右侧似乎不起作用

Android 对齐到相对布局的右侧似乎不起作用,android,android-relativelayout,Android,Android Relativelayout,我试图在父容器的右侧有两个文本视图,一个挨着另一个。 比如: +++++++++++++++++++++++++++++++++++++ (parent container) | TextView2 TextView1 | +++++++++++++++++++++++++++++++++++++ 以下方法不起作用,但我不明白为什么 <LinearLayout xmlns:android="http://schemas.android.com

我试图在父容器的右侧有两个文本视图,一个挨着另一个。
比如:

+++++++++++++++++++++++++++++++++++++  (parent container)  
|               TextView2 TextView1 |  
+++++++++++++++++++++++++++++++++++++    
以下方法不起作用,但我不明白为什么

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="100dp"
              android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:text="TEXTVIEW-1" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_toLeftOf="@id/textView1"
            android:layout_marginRight="1dp"
            android:text="TEXTVIEW-2" />

    </RelativeLayout>

</LinearLayout>

注:100dp仅用于显示问题

更新:
删除android:layout\u alignParentTop=“true”和android:layout\u alignParentRight=“true”后,我得到:


在第二个文本视图中,使用
android:layout\u-toLeftOf=“@id/textView1”
并删除
android:layout\u-alignParentTop=“true”
android:layout\u-alignParentRight=“true”

像这样:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="100dp"
              android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:text="TEXTVIEW-1"
            />
        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@id/textView1"
            android:layout_marginRight="1dp"
            android:text="TEXTVIEW-2"
            />

    </RelativeLayout>  

</LinearLayout>
因此,这意味着只有当
android:layout\u centerHorizontal
android:layout\u toStartOf
不存在时,
android:layout\u centerHorizontal
才会起作用

希望现在一切都清楚了。
如果有人找到这方面的文档,我很想了解一下优先顺序。

在第二个文本视图中,使用
android:layout\u toLeftOf=“@id/textView1”
并删除
android:layout\u alignParentTop=“true”
android:layout\u alignParentRight=“true”

  android:layout_alignParentRight="true"
像这样:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="100dp"
              android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:text="TEXTVIEW-1"
            />
        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@id/textView1"
            android:layout_marginRight="1dp"
            android:text="TEXTVIEW-2"
            />

    </RelativeLayout>  

</LinearLayout>
因此,这意味着只有当
android:layout\u centerHorizontal
android:layout\u toStartOf
不存在时,
android:layout\u centerHorizontal
才会起作用

希望现在一切都清楚了。 如果有人找到这方面的文档,我很想了解一下优先顺序

  android:layout_alignParentRight="true"
将其从textView2中删除


从textView2中删除此选项

从textView2中删除“layout_alignParentRight='true'”,从textView2中删除“layout_alignParentRight='true'”,此时两个选项都会显示,但TextView-1会垂直显示。我的意思是每个字母都在单独的行中,这是因为两个文本视图的宽度都比设置为100dp的容器的宽度大。将容器大小从100dp增加。如果你只想隐藏和显示单条线,并且隐藏溢出的内容,那么将显示该方法。因此,尽管我已将其左侧设置为忽略,以优先于对齐父项右侧?@Jim绝对正确。它将优先考虑
alignParentRight
。如果在LinearLayout中只有这两个文本视图,则可以删除RelativeLayout并将
android:gravity=“end”
设置为具有相同结果的LinearLayout(oreinetation:horizontal)。但这样我就需要按相反的顺序定义它们,对吗?两者现在都显示,但TextView-1现在垂直显示。我的意思是每个字母都在单独的行中,这是因为两个文本视图的宽度都比设置为100dp的容器的宽度大。将容器大小从100dp增加。如果你只想隐藏和显示单条线,并且隐藏溢出的内容,那么将显示该方法。因此,尽管我已将其左侧设置为忽略,以优先于对齐父项右侧?@Jim绝对正确。它将优先考虑
alignParentRight
。如果在LinearLayout中只有这两个文本视图,您可以删除RelativeLayout并将
android:gravity=“end”
设置为您的LinearLayout(或inetation:horizontal),结果相同。但这样我就需要按相反的顺序定义它们,对吗?