Adjust gridview between two views within a layout in android - 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.

Related

Scroll listview vertical and horizontal same image

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

ListView not getting space to show content on smaller screens

So I am developing a screen where there are some images and buttons on top and Below that is a list view which shows a list of some activity.
The design is something like this :-
Now on smaller screen the ListView height becomes very small as the screen space is taken up by the above icons and images.
So how can i increase the height of the Linearlayout or ListView so that user can scroll to the see the rest of the ListView.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
.... Other Layouts .....
<ListView
android:id="#+id/listArea"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:paddingLeft="#dimen/list_padding"
android:paddingRight="#dimen/list_padding" />
</LinearLayout>
Edit: Tried using the top view as a header to the List but since I want an EmptyView too, this is creating a problem as it replaces the whole header + listview
From what I read about that issue, you should specify the Views on top as header of the list, and the'll scroll properly.
Afaik this only works if the list is non-empty, as the empty view replaces the whole list including headers.
You can use the weightSum and layout_weight attributes to control how much of the parent's available space a child view will take up. To use these, a parent layout, for example, your LinearLayout, gets the android:weightSum attribute. Each child layout gets the android:layout_weight attribute, where the sum of all child weights is the weightSum of the parent. In addition, each child should have their layout_height or layout_width set to 0dp, whichever is going to be decided by the weight.
Here's an example based on your diagram. Let's say you want the two top views to take up 1/4 of the screen each, and the ListView to take up the bottom half. Add android:weightSum="4" to your LinearLayout, android:layout_weight="1" to the two child layouts that you represent with ...Other Layouts..., and android:layout_weight="2" to the ListView. Code might look something like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="4">
<ImageView
android:layout_weight="1"
android:layout_height="0dp"
...some other attributes.../>
<LinearLayout
android:layout_weight="1"
android:layout_height="0dp"
android:orientation="horizontal"
...some other attributes...>
...some children of the LinearLayout...
</LinearLayout>
<ListView
android:id="#+id/listArea"
android:layout_width="match_parent"
android:layout_height="0dp"
android:paddingLeft="#dimen/list_padding"
android:paddingRight="#dimen/list_padding"
android:layout_weight="2"/>
</LinearLayout>

It is possible create a layout and view flipper on the same line?

It is possible create a screen of the following way?
![Screen][2]
When I change of page, the same layout is displayed on every page
Regards
Yes, the layout is possible:
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ViewFlipper android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ViewFlipper>
<!-- I assumed your layout at the top-left corner is a LinearLayout, otherwise replace it with what you have -->
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="#+id/firstLayout">
</LinearLayout>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/firstLayout"
android:layout_margin="5dp"/>
</RelativeLayout>
Edit:
Your question is a little ambiguous, if you want to just add a TextView near the Layout element from your layout then add the TextView and set it an attribute of toRightOf(with some margin to put some gaps). Check the modification in the layout above. If you want the TextView to be vertical centered(taking in consideration the height of Layout) like in your picture then you could wrap the Layout and TextView in a LinearLayout with (width and height set to wrap_content) and aligned to top and left in the parent RelativeLayout.
Your question isn't really clear, but I suspect what you're looking for is exactly what Kursprog gave you, except that you want to put the top left layout and the text view into a wrapper Linear layout, so your xml would look like this (minus all the attributes).
<RelativeLayout> <!--Parent -->
<ViewFlipper/>
<LinearLayout android:orientation="horizontal"><!-- wrapper to your two top layouts
<LinearLayout/> <!-- whatever layout it is that you're describing in your diagram -->
<TextView/> <!-- the text view in your diagram -->
</LinearLayout>
</RelativeLayout>
You'll want to give the wrapper a width of fill_parent and set the layout_weight of both inner elements to 1, so that they're distributed evenly on the screen.
I solved the problem with the FrameLayout. The FrameLayout to allow overlap Views

Getting Views to fit

I have a main.xml with a LinearLayout with three items inside, LinearLayout, ListView and LinearLayout. I would like the ListView to be as big as possible while keeping the bottom LinearLayout always showing and not shrunk or knocked off the screen.
I have tried making the ListView height fillparent, but then the bottom LinearLayout doesn't show up, same with wrapcontent, since the ListView has lots of content.
When I make the ListView a set size, say 300dp, I have space below the bottom LinearLayout. I tried to fix this by making the top level LinearLayout gravity=fill, but that didn't help.
Also, depending on the android I try it on, the bottom LinearLayout will drop off the screen, or get shrunk.
In case it's relevant, the top level LinearLayout is set to fillparent for height.
My goal is to keep the top and bottom LinearLayout to wrap their content, and the middle ListView fill what's left... any suggestions?
Thanks in advance for your efforts!
I believe you can just add android:layout_weight="1" to the ListView, with the ListView set to a height of fill_parent, and the two LinearLayouts set to wrap_content. Regardless, I usually prefer to use a RelativeLayout. You can specify the header to align to the top of the screen, the footer to align to the bottom, and the ListView to fill the space in between, like so:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
>
//...insert stuff here
</LinearLayout>
<LinearLayout
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
//...insert stuff here
</LinearLayout>
<ListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/footer"
android:layout_below="#id/header"
/>
</RelativeLayout>

android horizontal scrollview

Hi
am testing horizontal scrollview i came to a strange problem ,i put one button in horizontal scrollview with layout height and width fill_parent but that tag have no effect in layout ,lets look in to my layout
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:fillViewport="true"
>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:text="Button"
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</Button>
</LinearLayout>
</HorizontalScrollView>
How can i fill the layout with my button inside horizontal scrollview
the problem might be in android:width="wrap_content"....
as u did wrap content for horizontal scrollview and it is parent of linearlayout and button in above case.......
that might be creating all the problem...
either hard code size of linear layout or put android:width="fill_parent" in horizontal scroll view.....
Remember that scroll view layout_height must be warp_content , fill_parent attribute does not affect on the scrollview height, if you want to fill whole screen by button in your layout you should mentioned the layout_height hard coded.
Put this two tag in HorizontalScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
Put orientation in LinearLayout
android:orientation="vertical"
Do android:layout_height="fill_parent" to android:layout_height="wrap_content" in HorizontalScrollView

Categories

Resources