Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android,自定义视图不';Don’不要把屏幕填满画廊_Android_Gallery_Android Viewpager - Fatal编程技术网

Android,自定义视图不';Don’不要把屏幕填满画廊

Android,自定义视图不';Don’不要把屏幕填满画廊,android,gallery,android-viewpager,Android,Gallery,Android Viewpager,我想显示一个自定义视图,由垂直线性布局中图像视图上方的文本视图组成,在库中一次显示一个 问题是我的自定义视图没有填满屏幕。我可以从侧面看到其他观点的一部分,我不想看到这个问题。 以下是我的自定义视图的xml:gallery\u item.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" an

我想显示一个自定义视图,由垂直线性布局中图像视图上方的文本视图组成,在库中一次显示一个

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

以下是我的自定义视图的xml:gallery\u 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>
谢谢你的帮助


Samuel

您应该同时使用textview和imageview fillparent的宽度。然后它将填充库的屏幕

我建议您使用ViewPager而不是Gallery。以我个人的经验,我发现画廊有点像马车。如果您的要求是一次只显示一个视图,那么ViewPager(它可以让您向左和向右滑动一个接一个)应该适合您的需要

要使用ViewPager,您需要包括Android支持包

链接到支持包:
有关如何使用ViewPager的链接:

感谢您的帮助。ViewPager正是我想要的!本教程工作良好,使用简单。
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;
}