2012-06-19 33 views
0

我想設計一個列表視圖,其中有3個textViews。 1個textview是作者,第二個是日期,最後一個是評論。但是,我在佈局方面遇到了一些問題,並且我不是XML中的怪物。所以我確實需要一些建議。這是我的列表看起來像atm:http://tinypic.com/view.php?pic=357khhj&s=6listview在android中的textviews

正如你所看到的,每當有人輸入更多然後幾個字(像jesper的評論),一切看起來很糟糕。任何提示如何我可以解決這一問題,沒有行獲取所有f`ked了像圖片?另外,我只希望能夠在註釋事件中顯示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

嘗試使用純的LinearLayout或RelativeLayout的,而不是TableLayout。 – azgolfer

回答

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 =「2」註釋的TextView將其限定爲兩行。

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>