Android 安卓相对长度和相等对齐

Android 安卓相对长度和相等对齐,android,android-relativelayout,Android,Android Relativelayout,我有一个表行设置使用相对布局。它有两个文本视图,我希望它们具有相等的间距和左对齐的文本。请参阅下面的当前设置。这有一个文本视图左对齐,另一个右对齐。当我更改为将两个内容重叠对齐到左侧时 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/LinearLayout0

我有一个表行设置使用相对布局。它有两个文本视图,我希望它们具有相等的间距和左对齐的文本。请参阅下面的当前设置。这有一个文本视图左对齐,另一个右对齐。当我更改为将两个内容重叠对齐到左侧时

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout02"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:padding="10dip">
    <TextView
         android:id="@+id/displayLabel"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_centerVertical="true"
         android:layout_marginLeft="20dp"
         android:layout_toRightOf="@+id/row_image"
         android:text="adasd"
         android:textSize="18sp" />    
    <TextView
        android:id="@+id/displayValue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="20dp"
        android:text="adasd"    
        android:textSize="18sp"/>

</RelativeLayout>


任何建议。提前感谢您的帮助。

您是否尝试将以下内容用于displayValue TextView而不是alignParentRight

android:layout_toRightOf="@id/displayLabel"

然后给一些左边距。

您是否尝试将以下内容用于displayValue TextView而不是alignParentRight

android:layout_toRightOf="@id/displayLabel"

然后给出一些左边距。

这似乎是加权线性布局的工作-显示两个大小相等的文本视图:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout02"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:padding="10dip">

    <TextView
         android:id="@+id/displayLabel"
         android:layout_width="0dp"
         android:layout_height="wrap_content"         
         android:layout_marginLeft="20dp"
         android:text="adasd"
         android:textSize="18sp" 
         android:layout_weight="1"/>

    <TextView
        android:id="@+id/displayValue"
        android:layout_width="0dp"
        android:layout_height="wrap_content"        
        android:layout_marginRight="20dp"
        android:text="adasd"    
        android:textSize="18sp"
        android:layout_weight="1"/>

</LinearLayout>    

然后在emulator中,它看起来像:

请注意文本视图和零
layout\u width
中的
layout\u weight
属性。基本上,这意味着视图将获得与指定权重成比例的额外自由空间量。因此,对于相等的权重,这些视图将具有相同的宽度


请参阅以获取更多参考。

这似乎是加权线性布局的工作-显示两个大小相等的文本视图:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout02"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:padding="10dip">

    <TextView
         android:id="@+id/displayLabel"
         android:layout_width="0dp"
         android:layout_height="wrap_content"         
         android:layout_marginLeft="20dp"
         android:text="adasd"
         android:textSize="18sp" 
         android:layout_weight="1"/>

    <TextView
        android:id="@+id/displayValue"
        android:layout_width="0dp"
        android:layout_height="wrap_content"        
        android:layout_marginRight="20dp"
        android:text="adasd"    
        android:textSize="18sp"
        android:layout_weight="1"/>

</LinearLayout>    

然后在emulator中,它看起来像:

请注意文本视图和零
layout\u width
中的
layout\u weight
属性。基本上,这意味着视图将获得与指定权重成比例的额外自由空间量。因此,对于相等的权重,这些视图将具有相同的宽度

有关更多参考,请参阅