0

我有一个列表视图,它从数据库中获取几列,并使用列表视图填充文本视图......但我有一个问题导致项目重叠......这是我想要做的: http://i .stack.imgur.com/AR5Jp.jpg

粗体文本将是静态的(取自@string),而灰色文本应取自数据库,该文本可能只是一个或多个单词。我的 .xml 文件:

<?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="wrap_content"
android:orientation="vertical"
android:padding="6dip" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/textView1"
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:visibility="invisible"/>
<TextView
    android:id="@+id/idTender"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"        
    android:text=""
    android:visibility="invisible" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/textView2"
    android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
    android:id="@+id/number"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/textView4"
    android:text="" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/textView2"
    android:text="@string/textView3"
    android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
    android:id="@+id/Text1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/textView4"
    android:text="" />  

<TextView
    android:id="@+id/textView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/textView2"
    android:text="@string/textView3"
    android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
    android:id="@+id/Text2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/textView4"
    android:text="" />   
</RelativeLayout>

我尝试了很多方法,通过使用 android:layout 之类的 bellow、alignleft 和与其他人一起测试.. 但我无法找到这个设计背后的逻辑..

所以如果你能帮我建立这个布局,那就太好了......

4

1 回答 1

0

左侧的标签应彼此水平对齐,或与左侧屏幕边框具有相同的边距。每个值标签应与标签右侧水平对齐。垂直对齐避免重叠的关键点是您将每个标签对齐到前一个值下方,而不是前一个标签。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:text="Number:"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView1"
        android:layout_alignBottom="@+id/textView1"
        android:layout_marginLeft="20dp"
        android:layout_toRightOf="@+id/textView1"
        android:text="myNumber"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="20dp"
        android:text="Text1:"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/textView3"
        android:layout_alignLeft="@+id/textView2"
        android:text="long text is long is long text long is text is very very long text is long text long is indeed very long text even longer than what you would expect"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView4"
        android:layout_marginTop="20dp"
        android:layout_alignLeft="@+id/textView3"
        android:text="Text2:"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/textView5"
        android:layout_alignLeft="@+id/textView4"
        android:text="Yay this is in the right position"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</RelativeLayout>

布局

于 2013-06-12T14:48:06.007 回答