Android布局上面一个FrameLayout,下面一个Gridview,如何让Gridview滚动的时候可以全屏滚动。
ringa_lee
ringa_lee 2017-04-17 16:37:39
0
5
582

1,Android布局上面一个FrameLayout,下面一个Gridview,如何让Gridview滚动的时候可以全屏滚动。

2,布局代码

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/anchor"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/grey_white"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="45.0dip"
        android:background="@drawable/top_bg" >

        <TextView
            android:id="@+id/activity_title"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:text="最新上映"
            android:textColor="@color/white"
            android:textSize="17.0dip" />
    </LinearLayout>

    <FrameLayout
        android:id="@+id/linearlayout_images_slide"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <android.support.v4.view.ViewPager
            android:id="@+id/image_slide_page"
            android:layout_width="fill_parent"
            android:layout_height="150dip"
            android:focusable="true" />

        <RelativeLayout
            android:id="@+id/layout_title_text"
            style="@style/Transparent"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_gravity="bottom"
            android:background="#55000000" >

            <RelativeLayout
                android:id="@+id/layout_bar_image"
                android:layout_width="match_parent"
                android:layout_height="1dip"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:background="@drawable/image_page_bg" />

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:orientation="horizontal" >

                <TextView
                    android:id="@+id/tvSlideTitle"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="10dp"
                    android:gravity="center_vertical"
                    android:textColor="@android:color/white"
                    android:textSize="12sp" />

                <LinearLayout
                    android:id="@+id/layout_circle_images"
                    android:layout_width="wrap_content"
                    android:layout_height="15sp"
                    android:layout_alignParentRight="true"
                    android:layout_marginRight="10dp"
                    android:layout_marginTop="10dp"
                    android:layout_toRightOf="@id/tvSlideTitle"
                    android:gravity="right|center"
                    android:orientation="horizontal" />
            </RelativeLayout>
        </RelativeLayout>
    </FrameLayout>

    <GridView
        android:id="@+id/anchor_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/title_bar_text"
        android:layout_marginLeft="0dip"
        android:layout_marginRight="5dip"
        android:cacheColorHint="#00000000"
        android:columnWidth="2dip"
        android:listSelector="#00000000"
        android:numColumns="3" >
    </GridView>

</LinearLayout>

3,图片
如图1,是没有拖动的图片,下面的图是拖动的效果。拖动的时候上面的幻灯不会动,所以只能拖动下面一点距离。

请问怎么样才可以下面的gridview往上拖动的时候。上面的幻灯也会向上滚动。

ringa_lee
ringa_lee

ringa_lee

reply all(5)
黄舟

Thank you for your answers, I finally solved it by adding a headview to the gridview.

For specific methods, please refer to this link: http://blog.csdn.net/zhzhyang0313/articl...

巴扎黑

I don’t know if the header of recyclerview can be solved, you can try it

http://www.open-open.com/lib/view/open1434422599926.html

刘奇

1. In fact, the entire interface can be implemented using recycleView+gridLayoutManager, so that you can slide directly.
2. If this is your layout, you can use the Scroller class in the ontouchEvent of the gridView to realize the sliding on it

左手右手慢动作

First you have to change the layout. The current layout cannot meet your needs. You can consider nesting GridView in ScrollView, which is a relatively simple implementation idea. With this solution, you need to solve the conflict problem between two scroll views. The solution to the problem is relatively easy. You can refer to this method to solve the conflict of ScrollView nested GridView

洪涛

Option 1: Use a ListView to implement it. The top slide is the HeaderView. The listview item layout uses two horizontal items, disables onItemClick, and manually adds click events to each item.

Option 2: Use recyclerView to implement. There are many open source components that can easily add headerview to recyclerview https://github.com/search?utf8=%E2%9C%93&q=header+footer+recyclerview, and then use gridLayoutManager Just come and realize it.

It is not recommended to use scrollview nested gridview to implement it. This is the same as scrollview+linearlayout and does not have the function of item reuse.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template