android中带文本视图的listview
我正在尝试设计一个包含3个文本视图的列表视图。1文本视图用于作者,2文本视图用于日期,最后一文本视图用于评论。但我在布局上遇到了一些问题,我不是XML中的怪物。所以我需要一些建议。这就是我的清单: 正如你所看到的,每当有人键入超过两个单词(如杰斯珀的评论)时,一切看起来都很糟糕。有什么建议吗?我怎么能在没有行的情况下解决这个问题?就像图中那样?。此外,我只希望能够在注释中显示2行文本,即使用户实际键入,例如10行。塔克斯 以下是xml代码:android中带文本视图的listview,android,listview,layout,textview,Android,Listview,Layout,Textview,我正在尝试设计一个包含3个文本视图的列表视图。1文本视图用于作者,2文本视图用于日期,最后一文本视图用于评论。但我在布局上遇到了一些问题,我不是XML中的怪物。所以我需要一些建议。这就是我的清单: 正如你所看到的,每当有人键入超过两个单词(如杰斯珀的评论)时,一切看起来都很糟糕。有什么建议吗?我怎么能在没有行的情况下解决这个问题?就像图中那样?。此外,我只希望能够在注释中显示2行文本,即使用户实际键入,例如10行。塔克斯 以下是xml代码: <?xml version="1.0" enco
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffff" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:weightSum="1.0" >
<TableRow>
<TextView
android:id="@+id/feedback_list_item_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_weight="0.8"
android:gravity="left"
android:shadowColor="#bdbebd"
android:shadowDx="1.0"
android:shadowDy="1.0"
android:shadowRadius="0.5"
android:text="Unknown"
android:textColor="#000000"
android:textSize="16dp"
android:textStyle="bold" />
<TextView
android:id="@+id/feedback_list_item_time"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_weight="0.2"
android:gravity="right"
android:shadowColor="#bdbebd"
android:shadowDx="1.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="00:00"
android:textColor="#3c6dae"
android:textSize="16dp" />
</TableRow>
<TableRow>
<TextView
android:id="@+id/feedback_list_item_comment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:shadowColor="#cccccc"
android:shadowDx="1.0"
android:shadowDy="1.0"
android:shadowRadius="0.5"
android:text="No comment"
android:textColor="#222222"
android:textSize="16dp" />
>
</TableRow>
</TableLayout>
</LinearLayout>
>
为表中的每一行使用RelativeLayout。例如,尝试使用以下代码代替您的两个TableRow:
<RelativeLayout
android:layout_height="wrap_content">
<TextView
android:id="@+id/feedback_list_item_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="left"
android:shadowColor="#bdbebd"
android:shadowDx="1.0"
android:shadowDy="1.0"
android:shadowRadius="0.5"
android:text="Unknown"
android:textColor="#000000"
android:textSize="16dp"
android:textStyle="bold"
android:lines="1"/>
<TextView
android:id="@+id/feedback_list_item_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:gravity="right"
android:shadowColor="#bdbebd"
android:shadowDx="1.0"
android:shadowDy="1.0"
android:shadowRadius="1.0"
android:text="00:00"
android:textColor="#3c6dae"
android:textSize="16dp" />
<TextView
android:id="@+id/feedback_list_item_comment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_alignParentLeft="true"
android:layout_below="@id/feedback_list_item_name"
android:shadowColor="#cccccc"
android:shadowDx="1.0"
android:shadowDy="1.0"
android:shadowRadius="0.5"
android:text="No comment"
android:textColor="#222222"
android:textSize="16dp"
android:maxLines="2" />
</RelativeLayout>
此外,将maxLines=“2”添加到注释文本视图会将其限制为两行。试试这一行
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true" />
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true" />
</LinearLayout>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:singleLine="true" />
</LinearLayout>
尝试使用纯线性布局或相对布局,而不是表格布局。