使相对布局中的两个文本视图占据高度的50%

And*_*kov 4 android android-layout

我有一个自定义列表视图,其中包含以下项目布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:paddingBottom="2dip"
    android:paddingTop="2dip" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:paddingLeft="6dip" />

    <TextView
        android:id="@android:id/text1"
        android:layout_width="50sp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@id/icon"
        android:ellipsize="marquee"
        android:gravity="center"
        android:paddingLeft="6dip"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/start_point"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@android:id/text1"
        android:ellipsize="marquee"
        android:paddingLeft="6dip"
        android:paddingRight="6dip"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/end_point"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_below="@id/start_point"
        android:layout_toRightOf="@android:id/text1"
        android:ellipsize="marquee"
        android:gravity="center_vertical"
        android:paddingLeft="6dip"
        android:paddingRight="6dip"
        android:singleLine="true"
        android:textAppearance="?android:attr/textAppearanceSmall" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

它显示大部分像我想要的除了那个start_point并且end_point高度不相等.我尝试过很多东西但是在语法错误或布局破坏方面都有所结束.有没有可行的解决方案来实现这一目标?

Luk*_*rog 5

除了start_point和end_point的高度不相等外,它主要表现得像我想要的.我尝试过很多东西但是在语法错误或布局破坏方面都有所结束.有没有可行的解决方案来实现这一目标?

在布局之前在布局中插入一个额外的视图,TextViews这将作为一个锚点,为以下内容提供相等的空间TextViews:

<RelativeLayout>
    // the icon and the first TextView here

    <View android:id="@+id/anchor" android:layout_centerVertical="true" android:layout_alignParentRight="true"      
        android:layout_width="2dp"
        android:layout_height="0dp"/>

    // the two TextView below it
   <TextView
       android:id="@+id/start_point" android:layout_above="@id/anchor" // the rest of the attributes />

   <TextView
       android:id="@+id/end_point" android:layout_below="@id/anchor" // the rest of the attributes />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)