2017-02-17 2 views
0

Ich möchte ein ImageView, 2 TextViews und ein Rating Bar in einem Knoten in benutzerdefinierte Liste Adapter angezeigt werden, aber es es beschneiden, wenn ich den Code hier ist der XML-Code von benutzerdefinierten Liste Here is the picture of listAndroid: Wie kann man benutzerdefinierte Listenansichten anpassen?

custom_list.xml

laufen
?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> 
    <ImageView 
     android:id="@+id/img" 
     android:layout_width="50dp" 
     android:layout_height="50dp"/> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="Name" 
     android:id="@+id/tv_name" 
     android:layout_column="2" /> 

</TableRow> 

<TableRow 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <TextView 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:id="@+id/tv_deal" 
     android:layout_column="2" 
     android:text="deals" /> 
</TableRow> 

<TableRow 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RatingBar android:id="@+id/rb_rating" 
     android:layout_column="2" /> 
</TableRow> 

+1

Gründe, warum Sie 'TableLayout' statt' RelativeLayout' verwenden? ... es scheint auch, dass das Problem nicht hier ist, aber im Layout, wo Sie eine Listenansicht haben – Selvin

+0

Ist Relative Layout wie folgt in benutzerdefinierten Layout? – SFAH

+0

ja es funktioniert. Veröffentlichen Sie Ihr Listview- oder Recyclerview-Layout –

Antwort

1

Verwenden Sie die folgenden XML-Code für Ihr Listview Item:

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

    <ImageView 
     android:id="@+id/img" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" /> 

    <TextView 
     android:id="@+id/tv_name" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/img" 
     android:text="Name" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

    <TextView 
     android:id="@+id/tv_deal" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/img" 
     android:text="deals" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 


    <RatingBar 
     android:id="@+id/rb_rating" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/tv_deal" /> 
</RelativeLayout> 
+0

Ja, Sie hatten Recht "RealtiveLayout" ist effizienter als Tabelle Layout – SFAH

Verwandte Themen