Dynamische Höhe für das ListView-Steuerelement Zeile in android

Sehe ich ein seltsames Verhalten mit meiner ListView, die ich kann nicht scheinen, um zu bekommen.

Ich habe eine ListView, die ist gefüllt mit einigen Daten. Jede Zeile enthält ein Bild und drei Beschriftungen. Hier mein XML-Code für die Zeile (ich bin aufblasen es in den Adapter zu getView - Methode):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:paddingTop="0dip"
     android:paddingBottom="0dip"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:orientation="horizontal">

    <ImageView android:id="@+id/Icon"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        android:padding="2dp"
        android:scaleType="fitCenter"
        android:contentDescription="@string/app_icon"/>

    <TextView android:id="@+id/TxtName"
         android:scrollHorizontally="false"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:textColor="@android:color/black"
         android:background="@color/list_bg1"
         android:layout_weight="2"
         android:padding="2dp"/>

     <TextView android:id="@+id/TxtPackage"
         android:scrollHorizontally="false"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:layout_weight="2"
         android:textColor="@android:color/black"
         android:background="@color/list_bg2"
         android:padding="2dp"/>

     <TextView android:id="@+id/TxtSource"
         android:scrollHorizontally="false"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:layout_weight="2"
         android:background="@color/list_bg3"
         android:textColor="@android:color/black"
         android:padding="2dp"/>
</LinearLayout>

Nun, was auch immer geht in die text-Felder können in beliebiger Länge (von ein paar Zeichen zu 80-100 Zeichen) und ich will die Beschriftungen nur wickeln und die Höhe der Zeile zu erweitern, um Platz für die Höhe des eingebundenen labels.

Doch die labels tun wickeln ok, aber die Höhe der Zeile nicht erweitern, daher die Unterseite der Etiketten beschnitten wird. Hier ist meine getView Methode:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    SetInfo app = (SetInfo)getItem(position);
    if(app == null)
        return null;

    LinearLayout row = (LinearLayout) (convertView == null
               ? LayoutInflater.from(context).inflate(R.layout.listitem, parent, false)
               : convertView);
    ((TextView)row.findViewById(R.id.TxtName)).setText(app.getName());
    ((TextView)row.findViewById(R.id.TxtPackage)).setText(app.getPackage());
    ((TextView)row.findViewById(R.id.TxtSource)).setText(app.getSource());
    if(app.getIcon() != null)
        ((ImageView)row.findViewById(R.id.Icon)).setImageDrawable(app.getIcon());
    return row;
}

Wie kann ich die Zeilen unterschiedlicher Höhe automatisch angepasst wird alle Inhalte?

Der bessere Weg die Verwendung von android:maxLines=1 in Textview im Layout der Reihe seiner Verhindern, dass mehr als eine Zeile text
Haben Sie versucht, adujusting android:layout_weight auf 1 oder so?
Ich will das genaue Gegenteil: die Etiketten MÜSSEN wickeln, wie ich brauche, dass der gesamte text sichtbar sein.
layout_weight auf welche Komponente? Ich benutze zum einstellen der Breite der einzelnen sub-views innerhalb der Reihe bereits, aber wie kann ich es nutzen, um stellen Sie die Höhe der Zeile?

InformationsquelleAutor Aleks G | 2012-03-01

Schreibe einen Kommentar