1

I want design layout same like my attached image, this listview can horizontal and vertical scroll. I create header A B C by gridview, but not add list view in the rest.

Image:

Image

  • 1
    I don't understand clearly your issue: can you explain a little more what do you expect, what did you try and what is the behaviour now? – Blo Mar 25 '14 at 09:16
  • i want create demo UI same image attach, i used scrollview, gridview and listview, but i create header (A B C like image) by gridview, part "content A"... i create by listview, but i not join them – user3401211 Mar 25 '14 at 09:28

2 Answers2

1

As I understand, you try to put above a ListView, a ScrollView or a GridView another GridView as an HeaderView which this scrolls horizontally. It seems like adding several widgets which have their own handling of scroll event.. Don't know if this is possible.

Try another way, change your GridView as a HorizontalScrollView and put your views A, B, C.. inside.

<HorizontalScrollView
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" >

        Here, your views A, B, C...

</HorizontalScrollView>

See an example of this simple layout: Scrollabale listview in both direction with header using Horizontal scrollview.

Then if you want to scroll the content but keep the header part fixed, try to add this layout above your content with a ViewGroup container (inside LinearLayout, RelativeLayout or something else) with an include:

<RelativeLayout
    ... >
    <include 
        android:layout="@layout/layout_horizontal_scrollview"
        ... >
    <ListView
        ... >
</RelativeLayout>

This should do the trick..

But if you want that your header part scroll at the sime time to your content, try to add this layout as a HeaderView (I've just try this, it works):

  1. Create an HorizontalScrollView for header:

    <HorizontalScrollView
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal" >
        Here, your views A, B, C...
    </HorizontalScrollView>  
    
  2. Inflate this layout as a HeaderView:

    View header = View.inflate(this, R.layout.layout_horizontal_scrollview, null);
    listview.addHeaderView(header);
    

Note: add a HeaderView to a GridView isn't possible, you could do this with a special adapter (like HFGridView).

Blo
  • 11,903
  • 5
  • 45
  • 99
  • This works, just tried it! The headerview has a horizontal scroll whereas your list has a vertical scroll and your header scroll with the content. You inflate the HorizontalScrollView with addHeaderView and it works. – Blo Mar 25 '14 at 10:24
0

Compose them (GridView and ListView) in RelativeLayout or vertical oriented LinearLayoutthis way:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

<GridView
    android:id="@+id/gridview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

<ListView
    android:id="@+id/listview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/gridview" >

</RelativeLayout>

Item to ListView is added programmatically by setting data to adapter.

Edit (enabling vertical and horizontal scroll): Try this How can I make my layout scroll both horizontally and vertically?.

Community
  • 1
  • 1
Yehor Nemov
  • 907
  • 2
  • 16
  • 31
  • But not vertical scroll and horizontal scroll – user3401211 Mar 25 '14 at 10:00
  • You mean you want to scroll them simultaneously? – Yehor Nemov Mar 25 '14 at 10:03
  • Your views within layout within `HorizontalScrollView` within `ScrollView` is the answer. Check edit above. – Yehor Nemov Mar 25 '14 at 10:11
  • @ghoshak OP's wanted a scrolling header not the content scrollable. This is not a good practice like you can read on comments above your links: http://stackoverflow.com/a/4492050/2668136 – Blo Mar 25 '14 at 10:33
  • @user3401211 In the case you want only scrolling (in both directions) header without scrolling content below it you could wrap only GridView in HorizontalScrollView and ScrollView. As I get GridView is header and ListView is content for you. – Yehor Nemov Mar 25 '14 at 12:14