質問

私はRelativeLayoutラインのアイテムとリストビューを使用したレイアウトに取り組んでいます。 LineItems自体は正しく表示されません。

問題がtxtVideoDurationのTextViewはなく底の行項目の一番上に描画されることです。あなたはtxtVideoDurationは、リストビューの下部に固定されることになっているXMLで見ることができるようにこのためtxtVideoTitleは0の高さを取得します。

私の目標は、レイアウトは、Googleが私を与えたチュートリアルに似ていることです。例:ます。http://android-developers.blogspot。 COM / 2009/02 /アンドロイドレイアウトトリック-1.htmlする

私は、Android 2.0.1を使用しています。私もListViewコントロールに出て変更を加えた例のレイアウトに差し込まれてきたと同じ動作が起こります。

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

この単純なケースでは動作します。これは、活動のためのルートXMLレイアウトです。上部にバグのあるコードは、リストビュー内の行項目です。 ListViewコントロール自体がそれを壊しているようだ。

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

これは、リストビューにラインアイテムを膨張getViewメソッドコードである。

    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;
}
役に立ちましたか?

解決

どのようにして、「バギー」あるあなたの行ビューを膨張していますか?コードスニペットを提供することができますか?

また、android:orientation="vertical"RelativeLayoutには有効ではありません。

他のヒント

これが受け入れ答えののコメントの中で答えました。ただ、それを明確にするために、これが答えです。

変更

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

タグに

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top