Android 文本视图左右对齐的水平布局

Android 文本视图左右对齐的水平布局,android,android-layout,Android,Android Layout,我有以下视图结构: ------------------------------------ ||------------||------------------|| ||Text View 1 || Long Text View 3|| ||------------||------------------|| ||------------||------------------|| ||Text 2 || View 4 || ||------------||--

我有以下视图结构:

------------------------------------
||------------||------------------||
||Text View 1 ||  Long Text View 3||
||------------||------------------||
||------------||------------------||
||Text 2      ||  View 4          ||
||------------||------------------||
------------------------------------
我想要以下行为:

  • 左栏与左栏对齐
  • 右列作为一个组与右边框对齐,而文本视图与左边框对齐
  • 只要有足够的空间供其他列使用,列就会扩展并占用空间
  • 如果空间不足,无法完全容纳两列,则水平空间将被分割1/2,文本视图将换行
  • 通过将两个垂直线性布局嵌套到水平线性布局中,我几乎实现了这一点。但是#3并不满意。如果我将左栏和右栏的权重都设置为1,即使有更多的空间,它们最多也会占用50%

    如何实现所需的布局

    我已经读过了,还有其他的答案。Relativelayout不起作用-在文本溢出的情况下,一列与另一列重叠。或者,如果我指定了“toTheRightOf”,则它将第一列完全放在左边,然后尝试以每行一个字符的垂直文本结尾来匹配右边的列

    我的xml:


    此代码正在为您运行

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >
    
    <RelativeLayout
        android:id="@+id/Sperator"
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" >
    
    </RelativeLayout>
    
    <RelativeLayout
        android:id="@+id/FirstLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@id/Sperator" >
    
        <TextView
            android:id="@+id/tvFirstLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="TextView"
            android:textSize="24sp" />
    
        <TextView
            android:id="@+id/tvFirstParagraph"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/tvFirstLabel"
            android:text="ASFDNASKLCFNLASKFKLACNKJCUKENFIWOCNAMSKLDJAIUEFBN" />
    
    </RelativeLayout>
    
    <RelativeLayout
        android:id="@+id/SecondLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@id/Sperator" >
    
        <TextView
            android:id="@+id/tvSecondLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="YourLongTextView"
            android:textSize="24sp" />
    
        <TextView
            android:id="@+id/tvSecondParagraph"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/tvSecondLabel"
            android:text="ASFDNASKLsdfnjsacjsbnfsbfjhsbfjdsbfjhsbvfjhsbvfjbskCFNLASKFKLACNKJCUKENFIWOCNAMSKLDJAIUEFBN" />
    
    </RelativeLayout>
    
    
    

    截图是


    这里是润农。。请试试这个

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity" >
    
        <RelativeLayout
                android:id="@+id/FirstLayout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:minWidth="100dp" >
    
                <TextView
                        android:id="@+id/tvFirstLabel"
                        android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:text="TextView"
                android:textSize="24sp" />
    
                <TextView
                        android:id="@+id/tvFirstParagraph"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_below="@id/tvFirstLabel"
                        android:text="fasfdsfsdfsdcvzxfasd" />
    
        </RelativeLayout>
    
        <RelativeLayout
                android:id="@+id/Sperator"
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@id/FirstLayout" >
    
        </RelativeLayout>
    
        <RelativeLayout
                android:id="@+id/SecondLayout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@id/Sperator"
                android:minWidth="100dp" >
    
                <TextView
                        android:id="@+id/tvSecondLabel"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentTop="true"
                        android:text="YourLongTextView"
                        android:textSize="24sp" />
    
                <TextView
                        android:id="@+id/tvSecondParagraph"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_below="@id/tvSecondLabel"
                        android:text="ASFDNASKLsdfnjsacjsbnfsbfjhsbfjdsbfjhsbvfjhsbvfjbskCFNLASKFKLACNKJCUKENFIWOCNAMSKLDJAIUEFBN" />
    
        </RelativeLayout>
    
    </RelativeLayout>
    
    
    

    我希望这对您有所帮助:)

    好的,下面的代码对我很有用。如果您想让面板宽度增加50%以上,请将android:layout\u width=“0dp”替换为两个相对长度的
    android:layout\u width=“wrap\u content”

    
    
    发布你的xaml,这样我们就有了一个起点。我认为阿卜杜勒·卡迪尔·努卡勒姆(Abdulkadir NURKALEM)有一个很好的方法。如果一个专栏很短,它会让另一个专栏增长50%以上吗?但你给了我这个想法。它看起来像以下结构:RelativeLayout(RelativeLayout(LinearLayout(TextView,TextView)),RelativeLayout(LinearLayout(TextView,TextView)))应该做这项工作如果这个答案对你有帮助,请检查这个答案:)
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity" >
    
        <RelativeLayout
                android:id="@+id/FirstLayout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:minWidth="100dp" >
    
                <TextView
                        android:id="@+id/tvFirstLabel"
                        android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:text="TextView"
                android:textSize="24sp" />
    
                <TextView
                        android:id="@+id/tvFirstParagraph"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_below="@id/tvFirstLabel"
                        android:text="fasfdsfsdfsdcvzxfasd" />
    
        </RelativeLayout>
    
        <RelativeLayout
                android:id="@+id/Sperator"
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@id/FirstLayout" >
    
        </RelativeLayout>
    
        <RelativeLayout
                android:id="@+id/SecondLayout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@id/Sperator"
                android:minWidth="100dp" >
    
                <TextView
                        android:id="@+id/tvSecondLabel"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentTop="true"
                        android:text="YourLongTextView"
                        android:textSize="24sp" />
    
                <TextView
                        android:id="@+id/tvSecondParagraph"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_below="@id/tvSecondLabel"
                        android:text="ASFDNASKLsdfnjsacjsbnfsbfjhsbfjdsbfjhsbvfjhsbvfjbskCFNLASKFKLACNKJCUKENFIWOCNAMSKLDJAIUEFBN" />
    
        </RelativeLayout>
    
    </RelativeLayout>