Frage

Ich arbeite an einem Layout, in dem ich ein Listview mit RelativeLayout Positionen verwenden. Die Lineitem selbst nicht richtig angezeigt.

Das Problem ist, dass die txtVideoDuration Textview an der Spitze der Position gezogen wird, statt der Unterseite. Aus diesem Grunde die txtVideoTitle eine Höhe von 0. bekommt Wie Sie die txtVideoDuration im XML sehen soll den Boden des Listview geklemmt werden.

Mein Ziel ist das Layout ähnlich dem Tutorial zu haben, die Google mir gab. Beispiel: http: //android-developers.blogspot. com / 2009/02 / android-Layout-Tricks-1.html

Ich bin mit Android 2.0.1. Ich habe sogar im Beispiel Layout mit out-Modifikation in die Listview eingesteckt und das gleiche Verhalten geschieht.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:id="@+id/imgVideoThumbnail"
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true"
    android:minHeight="64dip"
    android:layout_marginRight="6dip"
    android:src="@drawable/icon" />
<TextView 
    android:id="@+id/txtVideoDuration"
    android:layout_width="fill_parent"
    android:layout_height="26dip" 
    android:layout_toRightOf="@+id/imgVideoThumbnail"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:singleLine="true"
    android:ellipsize="marquee"
    android:text="0:00:00" />
<TextView
    android:id="@+id/txtVideoTitle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/imgVideoThumbnail"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_above="@+id/txtVideoDuration"
    android:layout_alignWithParentIfMissing="true"
    android:gravity="center_vertical"
    android:text="[Title]"
    android:textColor="#FFFFFF" />

</RelativeLayout>

Mit diesem einfachen Fall funktioniert. Das ist die Wurzel XML-Layout für die Aktivität. Der Buggy-Code an der Spitze ist die Einzelposten in der Listenansicht. Es scheint, dass das Listview selbst es bricht.

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

<ListView
    android:id="@+id/listVideoCatalog"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
<TextView
    android:id="@+id/txtName"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:text="Hello World" />
</RelativeLayout>
</merge>

Dies ist der getView-Code, der die Position in der Listview aufbläst.

    static class ViewHolder
{
    TextView txtTitle;
    ImageView imgThumbnail;
    TextView txtDuration;
    Uri videoLocation;
}

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
    ViewHolder holder;

    if(convertView == null)
    {
        LayoutInflater li = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = li.inflate(R.layout.listitem_videolineitem, null);
        holder = new ViewHolder();
        holder.txtDuration = (TextView) convertView.findViewById(R.id.txtVideoDuration);
        holder.txtTitle = (TextView) convertView.findViewById(R.id.txtVideoTitle);
        holder.imgThumbnail = (ImageView) convertView.findViewById(R.id.imgVideoThumbnail);
        convertView.setTag(holder);
    }
    else
    {
        holder = (ViewHolder) convertView.getTag();
    }

    VideoFile video = this.videos.get(position);
    holder.txtDuration.setText(millisToTimestamp(video.videoDuration));
    holder.txtTitle.setText(video.videoTitle);

            // Some debugger visual code.
    holder.txtDuration.setBackgroundColor(Color.GREEN);
    holder.txtTitle.setBackgroundColor(Color.CYAN);


    return convertView;
}
War es hilfreich?

Lösung

Wie aufblasen Sie Ihre Reihe Ansichten, die „Buggy“ sind? Können Sie einen Code-Schnipsel zur Verfügung stellen?

Auch android:orientation="vertical" ist nicht gültig für RelativeLayout.

Andere Tipps

Dies wurde in dem Kommentar der akzeptierten Antwort beantwortet. Nur um deutlich zu machen, das ist die Antwort:

Ändern

li.inflate(R.layout.listitem_videolineitem, null);

li.inflate(R.layout.listitem_videolineitem, parent, false);

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top