2016-11-05 11 views
0

Fragmentで動的に作成されたカスタムリストビューの要素の等幅スペースの設定に問題があります。すべての要素は同じリストビューに配置されます。カスタムビューで一意にする方法を考えてください。この画像をご覧ください。助けて。前もって感謝します!!!!どのようにアンドロイドで動的に作成されたカスタムリストビューの同じ外観を設定するには?

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 [here](https://developer.android.com/reference/android/widget/TableRow.LayoutParams.html)を使用できます – MeLine

+0

このweightsum牽引リストビューの間のスペースを増やしましたが、私は単一のリストビューの要素の間に等しいスペースを作る必要があります.. –

関連する問題