我正在尝试设计一个包含3个textView的列表视图。 1个textview用于作者,第2个用于日期,最后一个用于评论。但我在布局方面遇到了一些问题,而且我不是XML中的怪物。所以我确实需要一些建议。这就是我的列表看起来像atm:http://tinypic.com/view.php?pic=357khhj&s=6
正如你所看到的,只要有人输入更多信息(比如jesper的评论),一切都看起来很糟糕。如何在没有行的情况下解决这个问题的任何提示都会像图片中那样被解决?此外,我只希望能够在评论中显示2行文本,尽管人们实际上是类型,例如10行。感谢名单!
这是xml代码:
<?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>
答案 0 :(得分:0)
对表格的每一行使用RelativeLayout。例如。尝试使用以下代码代替两个TableRows:
<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 =&#34; 2&#34;评论TextView将它限制为两行。
答案 1 :(得分:0)
尝试这个
<?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>