我想顯示一個自定義視圖,該圖像由一個垂直LinearLayout中的ImageView上方的TextView組成,一次一個一個地位於一個圖庫中。Android,自定義視圖不會填充圖庫中的屏幕
的問題是,我的自定義視圖不填充屏幕。我可以看到其他觀點的一部分,我不想要這個問題。
這裏是我的自定義視圖的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;
}
謝謝你的幫助。
塞繆爾
謝謝您的幫助。 ViewPager正是我想要的!該教程工作正常,使用簡單。 – Samuel 2012-04-16 06:55:20
不客氣。 :) – sparkymat 2012-04-17 12:52:47