2012-04-13 73 views
0

我想顯示一個自定義視圖,該圖像由一個垂直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; 
} 

謝謝你的幫助。

塞繆爾

回答

0

我會建議你使用ViewPager而非畫廊。在我個人的經歷中,我發現Gallery略有漏洞。如果你的要求是一次只顯示一個視圖,那麼ViewPager(它可以讓你左右滑動一個接一個地點)應該滿足你的需求。

您將需要包含Android支持包以使用ViewPager。

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

+0

謝謝您的幫助。 ViewPager正是我想要的!該教程工作正常,使用簡單。 – Samuel 2012-04-16 06:55:20

+0

不客氣。 :) – sparkymat 2012-04-17 12:52:47

0

你應該使用的TextView和ImageView的兩個寬度fillparent.then這將是填補畫廊的屏幕...

相關問題