簡體   English   中英

網格視圖的自定義頂行

[英]Custom top row for gridview

我正在嘗試使gridview的第一行與其他行不同。 我使用以下代碼來實現您在屏幕快照中看到的內容。 現在唯一的問題是,當滾動時,第一行停留在該位置:

        <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>

我正在使用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>

現在,在您的代碼中,使用ScrollView不使用GridView滾動。

另請注意, ScrollView只能托管一個直接子級,因此需要額外的LinearLayout

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM