简体   繁体   English

网格视图的自定义顶行

[英]Custom top row for gridview

I am trying to make a gridview that has a different first row than the other rows. 我正在尝试使gridview的第一行与其他行不同。 I used the following code to achieve what you can see in the screenshot. 我使用以下代码来实现您在屏幕快照中看到的内容。 The only problem now is that when you scroll the top row stays there: 现在唯一的问题是,当滚动时,第一行停留在该位置:

        <LinearLayout
            android:id="@+id/firstImages"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/imageFirst"
                android:layout_weight="2"
                android:scaleType="fitCenter"
                android:adjustViewBounds="true"
                android:layout_width="0dp"
                android:layout_height="wrap_content" />
            <LinearLayout
                android:orientation="vertical"
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="wrap_content">
                <ImageView
                    android:id="@+id/imageSecond"
                    android:scaleType="fitCenter"
                    android:adjustViewBounds="true"
                    android:layout_width="match_parent"
                    android:layout_weight="1"
                    android:layout_height="0dp" />
                <ImageView
                    android:id="@+id/imageThird"
                    android:scaleType="fitCenter"
                    android:adjustViewBounds="true"
                    android:layout_width="match_parent"
                    android:layout_weight="1"
                    android:layout_height="0dp" />
            </LinearLayout>
        </LinearLayout>
        <GridView
            android:id="@+id/catchesGrid"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/firstImages"
            android:layout_above="@+id/dealersFooter"
            android:numColumns="3"
            android:stretchMode="columnWidth"
            android:layout_alignParentEnd="true">

        </GridView>

I am showing the images using Picasso: 我正在使用Picasso显示图像:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    SquaredImageView view = (SquaredImageView) convertView;
    if (view == null) {
        view = new SquaredImageView(context);
        view.setScaleType(CENTER_CROP);
    }

    Catch catchItem = getItem(position);

    String url = "image_url";

    Picasso.with(context) //
            .load(url) //
            .fit() //
            .into(view);

    return view;
}

在此处输入图片说明

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/firstImages"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <ImageView
                    android:id="@+id/imageFirst"
                    android:layout_weight="2"
                    android:scaleType="fitCenter"
                    android:adjustViewBounds="true"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content" />
                <LinearLayout
                    android:orientation="vertical"
                    android:layout_weight="1"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content">
                    <ImageView
                        android:id="@+id/imageSecond"
                        android:scaleType="fitCenter"
                        android:adjustViewBounds="true"
                        android:layout_width="match_parent"
                        android:layout_weight="1"
                        android:layout_height="0dp" />
                    <ImageView
                        android:id="@+id/imageThird"
                        android:scaleType="fitCenter"
                        android:adjustViewBounds="true"
                        android:layout_width="match_parent"
                        android:layout_weight="1"
                        android:layout_height="0dp" />
                </LinearLayout>
            </LinearLayout>
            <GridView
                android:id="@+id/catchesGrid"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/firstImages"
                android:layout_above="@+id/dealersFooter"
                android:numColumns="3"
                android:stretchMode="columnWidth"
                android:layout_alignParentEnd="true">

            </GridView>

        </LinearLayout>

    </ScrollView>

Now in your code, scroll using the ScrollView do not scroll using the GridView. 现在,在您的代码中,使用ScrollView不使用GridView滚动。

Also note that ScrollView can only host one direct child, hence the extra LinearLayout . 另请注意, ScrollView只能托管一个直接子级,因此需要额外的LinearLayout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM