简体   繁体   中英

android two scroll horizontal and vertical in one activity

i want activity like image:

在此输入图像描述

I want in area 1 (in image) hold 4 button/image button can scroll horizontal.
Or it hold listview has 4 textview can scroll horizontal.
(may be it will be like google play app)
how to do it?

For the area1 use HorizontalScrollView and put the all the 4 buttons/ImageView and in below area put GridView like below:-

<LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:orientation="vertical">
    <HorizontalScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:orientation="horizontal">
            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_launcher"/>
            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_launcher"/>
            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_launcher"/>

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_launcher"/>
            </LinearLayout>
        </HorizontalScrollView>
        <GridView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:numColumns="4"
            android:columnWidth="30dp"></GridView>
</LinearLayout>

try the above it may help you

Please use Recyclerview in that area. When you use a RecyclerView, you need to specify a LayoutManager that is responsible for laying out each item in the view. The LinearLayoutManager allows you to specify an orientation, just like a normal LinearLayout would.

To create a horizontal list with RecyclerView, you might do something like this:

LinearLayoutManager layoutManager
    = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);

RecyclerView myList = (RecyclerView) findViewById(R.id.my_recycler_view);
myList.setLayoutManager(layoutManager);

https://developer.android.com/training/material/lists-cards.html

divide your screen into two layout, each of them has a scroll view like this

//Scroll 1
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="0"
    android:layout_weight="1">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        //4 button/img button

    </Linearlayout>
</ScrollView>

//Scroll2
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="0"
    android:layout_weight="1">
    <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:orientation="vertical">
         //gridview
    </LinearLayout>

</ScrollView>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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