2016-11-05 46 views
0

我在爲片段中動態創建的自定義列表視圖的元素設置等寬空間時出現問題。所有元素都排列在同一個listview中。請給出一個想法,以便如何使它在自定義視圖中獨一無二。請參閱此圖像。幫我。提前致謝!!!!如何在Android中爲動態創建的自定義列表視圖設置相同的外觀?

Screeshort of my design.

代碼------>

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


    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="20dp" 
     android:textSize="18sp" 
     android:textColor="#800080" 
     android:id="@+id/txt1"> 
    </TextView> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="20dp" 
     android:textSize="18sp" 
     android:textColor="#800080" 
     android:id="@+id/txt2"> 
    </TextView> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="20dp" 
     android:textSize="18sp" 
     android:textColor="#800080" 
     android:id="@+id/txt3"> 
    </TextView> 
    <Button 
     android:id="@+id/del_button" 
     android:text="Delete" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:onClick="addItems" 
     android:layout_gravity="right" 
     android:theme="@style/MyButton"/> 

</TableRow> 

回答

0

我覺得這是更好的辦法是使用GridView控件。你沒有提供ListView的代碼,但我認爲TableLayot和TableRow是無用的。但無論如何,您可以嘗試將TextView和Button放在LinearLayout中,並給它們一些權重。 前面的例子,給他們平等的空間:

<LinearLayout 
     android:id="@+id/horizontal_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="4" > 

<TextView 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:padding="20dp" 
    android:textSize="18sp" 
    android:textColor="#800080" 
    android:id="@+id/txt1"> 
</TextView> 

<TextView 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:padding="20dp" 
    android:textSize="18sp" 
    android:textColor="#800080" 
    android:id="@+id/txt2"> 
</TextView> 
<TextView 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:padding="20dp" 
    android:textSize="18sp" 
    android:textColor="#800080" 
    android:id="@+id/txt3"> 
</TextView> 
<Button 
    android:id="@+id/del_button" 
    android:text="Delete" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:onClick="addItems" 
    android:layout_gravity="right" 
    android:theme="@style/MyButton" 
    android:layout_width="0dp" 
    android:layout_weight="1" 
    /> 
</LinearLayout> 
+0

對不起。這不適合我..請給我一些其他的想法.. –

+0

您可以使用TableRow.LayoutParams [這裏](https://developer.android.com/reference/android/widget/TableRow.LayoutParams.html) – MeLine

+0

This權重增加了兩個listview之間的空間,但是我需要在單個listview的元素之間做出相等的空間。 –

相關問題