Scroll listview vertical and horizontal same image - android

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:

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):
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>
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).

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

Related

Disabling the scroll of ListView inside a ScrollView

I have a ScrollView. Inside it I have a list view which has its own scroll mechanism. However I have certain items inside the list view which works only with the listView scroll i.e not all the items are displayed of the list view inside the parent layout.
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
// SOME CODE
<ListView
android:id="#+id/latsttrans"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="1" >
</ListView>
// SOME CODE
</ScrollView>
I want to disable the scroll of listview so that I can access the parent layout and the listview items with the ScrollView itself.
Any ideas ?
Try LinearLayout instead of ListView and add child views in linear layout using addChild() method of LinearLayout. Inflate views using LayoutInflater and add those to LinearLayout.

Why is Horizontal Scrolling is not working when a List View is placed inside a horizontal ScrollView?

I have a simple list view which is placed inside a Horizontal Scroll view so that I can scroll horizontally when the list view content is too long. When I place Text View inside the horizontalScrollView, I could scroll horizontally. But, with list view it doesn't work.
Any body had the same issue? Any work around for this?
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/newListBoxContainerHSV"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="#FF00FF">
<ListView
android:id="#+id/list_view"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#FFFF00"
>
</ListView>
</HorizontalScrollView>
Because ListView is not meant to be put inside any ScrollView. It's considered a bad practice, as ListView itself has a built-in ScrollView and you may use it, so try avoiding at any price a ListView inside a ScrollView.
If necessary, redesign your layout to not need it, as it goes against Android's design.

Adjust gridview between two views within a layout in android

In my application, I have a layout which includes a LinearLayout--> Top, GridView--> Middle and a set of views which should be aligned to the bottom.
1. Layout when gridview is not having much content
2. Layout when grid view contents are increased
3. Layout as how it should be shown when Gridview content is very large
Presently my gridview is expanding when the contents in it is increasing that the lower level contents are not visible in the screen.
I don't want to assign specific height to the grid view as it is looking weird in screens with different dimensions.
Is there any way that the gridview expands only upto the bottom views? My parent layout is LinearLayout. I have tried out with relative layout, but it is not working.
I too faced the same problem and found the solution by modifying the respective xmls as below:
Use RelativeLayout as Parent Layout.
Place the Header Content in RelativeLayout
Use ScrollView for the GridView which changes dynamically.
Place the Footer Layout after ScrollView
as shown below:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/txtTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ScrollView
android:id="#+id/scro1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/txtTextView" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<GridView
android:id="#+id/scro1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
android:layout_below attribute in ScrollView makes the difference.

how to fit a large layout within a single screen with multiple listviews

i am working with a project in which what i have to do that there are two lists and the layout is very large you can say that it is just double to a normal layout. i have to add scroll view to show whole layout but the problem is that there can't be a list within a scroll view if i do so then there is ambiguity to compiler that which is scrolling if it is list or scroll view . Now what should i do help me thanks in advance ...
I am also attaching an image which is half of my layout....
From your query i designed one sample XML file :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffffff" >
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffffeabc" >
</LinearLayout>
</LinearLayout>
</ScrollView>
In above you will have Scroll View for larger height Views and also you have equal proportion of list View. Thing you have to concentrate is on android:layout_weight , you should check how to play using Weight attributes
Edit :
Okay one thing you can do is that , We can use Header footer concept of List View - make ImageView and 2nd List View as footer of 1st List View so that ImageView and 2nd ListView will always comes Below 1st List View..
For Header Footer concept check this Link.

Scrolled but till header visible in listview in android

I create a listview and that listview has a header. I use addHeaderView() method. But when i scroll down in listview the scrollbar vanishes. Is there any way to avoid this i.e i want to show the header all the times, if scrolled still it will show.
To do that you can't do that with the addHeaderView() method.
If you want to place a header on top you should place that in the layout, something like this.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/titleBarText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Title"/>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
The widget is behaving as intended. For what you need, you need to create a relativelayout with TextView at top followed by listview. The textview would act as the header and be static irrespective of your scroll.

Categories

Resources