0

我想显示一个自定义视图,由垂直 LinearLayout 中的 ImageView 上方的 TextView 组成,在画廊中一次一个。

问题是我的自定义视图没有填满屏幕。我可以看到侧面的其他观点的一部分,我不想要这个问题。

这是我的自定义视图的 xml:gallery_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gallery_item_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
>
    <TextView
        android:id="@+id/gallery_item_cardname"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textSize="20dp"
        android:textStyle="bold"
        android:text="@string/contrebandiers_lvl1"
        android:textColor="@android:color/darker_gray"
    />
    <ImageView
        android:id="@+id/gallery_item_cardimg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerInside"
        android:contentDescription="@string/app_name"
        android:src="@drawable/contrebandiers_lvl1"
    />
</LinearLayout>

这是我的适配器的 getVew 方法的代码:GTRoundDeckAdapter

public View getView(int position, View convertView, ViewGroup parent)
{
    GalleryItem galleryItem;

    if(convertView == null)
    {
        galleryItem = new GalleryItem();
        convertView = mInflater.inflate(R.layout.gallery_item, null);
        galleryItem.cardName = (TextView) convertView.findViewById(R.id.gallery_item_cardname);
        galleryItem.cardImg = (ImageView) convertView.findViewById(R.id.gallery_item_cardimg);
        convertView.setTag(galleryItem);
    }
    else
    {
        galleryItem = (GalleryItem) convertView.getTag();
    }

    GTCard gtCard = (GTCard) mRoundDeck.get(position);
    galleryItem.cardName.setText(gtCard.getNameId());
    galleryItem.cardImg.setImageResource(gtCard.getImgId());

    return convertView;
}

我感谢你的帮助。

塞缪尔

4

2 回答 2

0

您应该同时使用 textview 和 imageview fillparent 的宽度。然后它将填满画廊的屏幕...

于 2012-04-13T06:26:20.487 回答
0

我建议您使用 ViewPager 而不是 Gallery。以我个人的经验,我发现 Gallery 有点问题。如果您的要求是一次只显示一个视图,那么 ViewPager(它可以让您左右滑动以逐个浏览)应该适合您的需求。

您需要包含 Android 支持包才能使用 ViewPager。

支持包链接:http: //developer.android.com/sdk/compatibility-library.html 关于如何使用 ViewPager 的链接:http: //blog.stylingandroid.com/archives/537

于 2012-04-13T06:27:44.323 回答