I have a list view , where i am adding headerview to that list . every thing fine , but when am scrolling list headerview also moving with list, so i want to avoid headerview scrolling , i mean i have to scroll only list when i list reached to topview (titlebar), headerview has to remain bottom of titlebar .
can any one gimme a solution for this ?
Instead of a header use the following layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
--> Your header layout here
</LinearLayout>
<ListView android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" />
</LinearLayout>
Important things to notice:
The id of the ListView must be #android:id/list in order to be able to use a ListActivity
Use a 0 height and set the weight to 1
For me it worked fine when i included a tag called <include> before my listview,
the code was something like this
<include layout="#layout/stationlist_header"/>
<ListView
android:id="#+id/mylist"
android:layout_width="match_parent"
android:layout_height="210dp"
android:layout_gravity="bottom"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
>
</ListView>
I'm not sure I correctly understand what you ask.
So I get you have something like.
<ListView>
<Header />
<Item />
<Item />
<Item />
</ListView>
Why don't you do
<Header />
<ListView>
<Item />
<Item />
<Item />
</ListView>
?
Instead of adding a Header view add the view directly to the layout above the list view.
I had implemented all my list view like this all of them work grt..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/RelativeLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView android:id="#+id/title_top_refine_search" android:layout_width="fill_parent"
android:layout_height="45dip"
android:src="#drawable/title_bar_top"
android:scaleType="fitXY"
android:layout_alignParentTop="true" >
</ImageView>
<TextView android:id="#+id/TextView01" android:textColor="#FFFFFF" android:layout_marginTop="5dip"
android:textStyle="bold" android:gravity="center" android:textSize="23dip"
android:text="Refine Search" android:layout_width="fill_parent" android:layout_height="wrap_content"></TextView>
<ListView android:id="#+id/ListView01"
android:layout_below="#+id/title_top_refine_search"
android:layout_alignParentBottom="true"
android:layout_height="fill_parent"
android:layout_width="fill_parent"> </ListView>
</RelativeLayout>
A Layout Sample Containing header view and List view below
Related
I am trying to implement a premade library downloaded from a site to use it in my listview. It's called expandable listview, and I think we all know what that is.
In the XML file listview is like this:
<?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="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/text"
android:text="Hello World"/>
<!-- this is the button that will trigger sliding of the expandable view -->
<Button
android:id="#+id/expandable_toggle_button"
android:text="More"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/text"
android:layout_alignParentRight="true"
android:layout_alignTop="#id/text"/>
</RelativeLayout>
<!-- this is the expandable view that is initially hidden and will slide out when the
more button is pressed -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:id="#+id/expandable"
android:background="#000000">
<!-- put whatever you want in the expandable view -->
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:text="Action A" />
<Button
android:id="#+id/details"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:text="Action B"/>
</LinearLayout>
</LinearLayout>
As we all know, an array list needs the listview to be just textview to work, otherwise it throws exception.
Can some one guide me how these things work on array list?
You can use custom adapter for this. See this link for tutorial on how to. :)
I was trying to use relative layout but the header becomes in front of the text. So all was going to wrong direction.
My app screen looks like:
I would like to add also footer but every time I try it fails. Im pretty sure that all widths and heights are okay in my xml layout.
Here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/item1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:height="30dip"
android:text="#string/item1" />
<TextView
android:id="#+id/item2"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:height="30dip"
android:text="#string/item2" />
<TextView
android:id="#+id/item3"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:height="30dip"
android:text="#string/item3" />
<TextView
android:id="#+id/item4"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight=".25"
android:height="30dip"
android:text="#string/item4" />
</LinearLayout>
<!-- List Divider -->
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="?android:attr/listDivider" />
<!-- ListView (grid_items) -->
<LinearLayout
android:id="#+id/layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ListView>
</LinearLayout>
</LinearLayout>
Please give me any suggestion. I think that relative layout would be great idea but I do not know much about it yet.
1/ Use a RelativeLayout for 'main'.
2/ Add the attribute android:layout_alignParentTop="true" to 'header'.
3/ Remove the LinearLayout with id 'layout', it's not needed.
4/ Add your footer to the end of the XML. When specifying its id, use #id not #+id. Give it an attribute android:layout_alignParentBottom="true".
5/ Add the following attributes to the ListView:
android:layout_below="#id/header"
android:layout_above="#+id/the_id_you_give_the_footer"
In my layout, I need a header, a list-view, and a footer with a TextView. The TextView needs to be resizable to up to 5 lines. Think facebook chat, where you have the blue header with the name of your friend, the middle content pane, and a text box down below, that grows as you type stuff in:
[header] a fragment that takes up about 50dp
[content]
[content]
[content]
[content] something like a ViewGroup with a ListView in it
[content]
[content]
[content]
[footer] a ViewGroup that contains an EditText and Buttons
I've tried all sorts of different layout settings, but can't get it right. Either the footer takes up all the space, or the content covers the footer.
Here's what I have so far:
<LinearLayout ...>
<!-- Slot to put Header fragment in -->
<FrameLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- Here's where the content goes. This is supposed to be a ListView
inserted as a fragment -->
<FrameLayout
android:id="#+id/content"
... />
<include
android:id="#+id/footer"
... />
</LinearLayout>
I left out the layout_width and layout_height values empty, because I don't know what to set them to.
UPDATES
Initially, I thought the problem was because my EditText was set to maxLines=5 and TextMultiline, but I tried removing everything but one button with a hardcoded height, and the insert still covered everything. I also tried setting <footer below="content"> but then content just covered footer
The problem was that the footer layout included is another RelativeLayout. The footer layout contains elements that set layout_alignParentBottom="true", which made the footer layout take up the entire screen. I have no idea why it would do that, but that's what happens.
For creating a UI like this create a layout
header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:text="xyz"
android:textSize="10dp" />
</LinearLayout>
for footer:
footer.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:text="xyz"
android:textSize="10dp" />
</LinearLayout>
Create another layout that will contain listView as you said :
main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical" >
**<include layout="#layout/header.xml" android:layout_alignParentTop="true"/>**
<ListView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
>
</ListView>
**<include layout="#layout/footer.xml" android:layout_below="#+id/listview" android:layout_alignParentBottom="true"/>**
</RelativeLayout>
check this...I hope it helps. At the moment I have defined an array.xml in Values folder with some empty entries for ListView. You will have to handle it with code.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="HEADER" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/chats"
android:layout_weight="1">
</ListView>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="5"
android:inputType="textMultiLine"
android:hint=" Please enter your Chat" />
</LinearLayout>
I'm trying to put a ProgressBar view below a ListView for a ListActivity. I want it to be always below the last row in the listView.
The ProgressBar, which is placed in a LinearLayout, does appear, as long as the list (which is filled by an adapter at runtime) is not exceeding the screen. As soon as the list is larger than the screen, the ProgressBar is no longer visible.
The layout xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/db1_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<!-- Title bar -->
<LinearLayout
style="#style/TitleBar" >
<TextView
style="#style/TitleBarText"
android:text="Some title text" />
<ImageButton
style="#style/TitleBarAction"
android:contentDescription="#string/description_search"
android:src="#drawable/title_search" />
</LinearLayout>
<!-- Content -->
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent" >
<ListView
android:divider="#drawable/category_item_divider"
android:dividerHeight="#dimen/list_divider_height"
android:layout_height="wrap_content"
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_weight="1" />
<TextView
android:id="#+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/category_no_items" />
</LinearLayout>
<!-- Progress bar -->
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content" >
<ProgressBar
android:id="#+id/productlist_progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
Is this not possible with a LinearLayout? Any help appreciated.
You should add a footer using :
list.addFooterView(footerView);
or doing it manually, but then consider using relative layouts, there are far more powerfull than linear layouts. And then place your footer below the list, or better, place your list and your empty view above your footerview.
I have a listactivity with the following layout-xml
<?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"
xmlns:myapp="http://schemas.android.com/apk/res/se.javalia.myDrinks"
>
<Button android:id="#+id/saveButton"
android:text="test test"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/main_no_items" />
</LinearLayout>
Now, I'd like to add a button above the list that stays in place when the list is scrolled.
Is it possible at all?
Thanks in advance
Roland
It's definitely possible, just add a Button before the ListView in your XML. If your View becomes more involved, I would change your LinearLayout to be a RelativeLayout, and then you can position the elements more easily.
Yes, just add a button above the ListView.
In your 1st LinearLayout you should add: android:orientation="vertical"