Question

Je travaille sur une mise en page où j'utilise un ListView avec des articles en ligne RelativeLayout. Les LineItems eux-mêmes ne sont pas affichés correctement.

Le problème est que la txtVideoDuration TextView est tiré en haut de l'élément de ligne au lieu du fond. En raison de cette txtVideoTitle obtient une hauteur de 0. Comme vous pouvez le voir dans le XML le txtVideoDuration est censé être serré au fond du ListView.

Mon but est d'avoir la mise en page ressemble le tutoriel que Google m'a donné. Exemple: http: //android-developers.blogspot. com / 2009/02 / android-layout-tours-1.html

J'utilise Android 2.0.1. J'ai même branché dans la mise en page d'exemple avec des modifications dans le ListView et le même comportement se produit.

<?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>

Cette affaire simple fonctionne. Ceci est la mise en page XML racine pour l'activité. Le code bogué en haut est les postes dans la vue de la liste. Il semble que le ListView lui-même est le casser.

<?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>

Voici le code getView qui gonfle l'élément de ligne dans le ListView.

    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;
}
Était-ce utile?

La solution

Comment êtes-vous gonflez vos vues de ligne qui sont « buggy »? Pouvez-vous fournir un extrait de code?

En outre, android:orientation="vertical" est pas valable pour RelativeLayout.

Autres conseils

a répondu dans le commentaire de la réponse acceptée. Juste pour préciser, voici la réponse:

Modifier

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

à

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top