http://realdevs.tistory.com/entry/asdf
↑ Picture.
I have a problem when I use ListView.
As the screen is full of widgets, I would like the ListView's items to be scrolled with other items in the layout.
On the picture, the blue one is a widget on the layout, and the red ones are the items of ListView.
When I scroll up the items, they move, but the blue one doesn't.
How can I make it to move together with ListView as it is an item in ListView?
you an add your blue layout as your listView header.
this will help you in adding a layout as header.
Simply add that blue part in scrollview
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
your layout
........
</ScrollView>
From your pic in http://realdevs.tistory.com/entry/asdf
I'm implement in coding xml 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">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#e0e0e0"
android:orientation="vertical" >
<!-- this layout add your other items. I'm exam add Button -->
<Button
android:id="#+id/butonTop"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:text="Top Button" />
</LinearLayout>
<!-- ListView in bottom screen and can auto scroll. -->
<ListView
android:id="#+id/dataListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:drawSelectorOnTop="false" >
</ListView>
</LinearLayout>
Related
I am having a ListView . It always has few items say 4 or 5 so it easily fits in the screen.
I am also having some view at bottom of the screen which is transparent.
My issue is the last item of listview is only partially visible because of view at bottom so I want to make that list item also to scroll till middle of the screen so that its details are visible. Any suggestions for doing this.
try this, Use Relative parent layout.
<?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"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linear_footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<EditText
android:id="#+id/edt_enter_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/editfield_selector"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:singleLine="true" />
<Button
android:id="#+id/btnsend"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#drawable/next_btn_selector"
android:gravity="center"
android:text="send"
android:textColor="#color/white" />
</LinearLayout>
<ListView
android:id="#+id/listView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#color/white"
android:layout_above="#+id/linear_footer"
android:divider="#null"
android:listSelector="#android:color/transparent" >
</ListView>
You should add INVISIBLE footerView which has LayoutParams the same as "Some other view" to your listView.
something like:
View view = findViewById(R.id.other_view);
view.setVisibility(View.INVISIBLE);
yourListView.addFooterView(view);
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>
Say I wanted to list buttons so that the last one was anchored to the bottom of the screen, how would I go about this. From my understanding, LinearLayout will give me the 'list' of buttons but it will be anchored to the top. RelativeLayout, on the other hand, will allow me to anchor to the bottom but each and every element will have to have a reference to the next element and the XML file will be in reverse order (so that references are valid).
How should I approach this?
EDIT: Apologies, this would be roughly what I would be looking for -
You can try adding an extra LinearLayout with a weight of 1 to take up all of the remaining space, and push the list of buttons to the bottom of the Activity:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
</LinearLayout>
<Button
android:id="#+id/widget33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
Sample XML is for a single button that gets pushed by a LinearLayout to the bottom of the Activity; root layout is Linear too.
i have a hard time understanding your question exactly.
But i assume that what you want is a horizontal list of buttons which is anchored to the bottom of the screen?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- put your other views in here -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal" >
<Button
android:id="#+id/button_cancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="cancel" />
<Button
android:id="#+id/button_ok"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
android:text="ok" />
</LinearLayout>
</LinearLayout>
i am the new android development.i got one problem i.e. in my application i added listview for the activity.after listview i added one linear layout in that i took one imageview and textview.my problem is for this one it cannot show the last row in the emulator but it displays the imageview and textview.but its not displaying the last row of the listview.i cannot understand what is the problem having so can you know please help my xml code is below see it once....
-->
<LinearLayout
android:id="#+id/search_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<AutoCompleteTextView android:id="#+id/autocomplete_country"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:singleLine="true"
android:hint="Search"/>
</LinearLayout>
<!-- <ScrollView android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"> -->
<ListView android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/search_layout"
android:layout_centerHorizontal="true"
android:layout_above="#+id/ban_layout"/>
<!-- </ScrollView> -->
</RelativeLayout>
<!-- </ScrollView> -->
<!-- <RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"> -->
<!-- </RelativeLayout> -->
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#id/listview"
android:background="#android:color/black"
android:id="#+id/ban_layout">
<ImageView
android:src="#drawable/orbit"
android:layout_width="50dip"
android:layout_height="50dip"
android:scaleType="fitCenter"/>
<TextView android:text="TextView"
android:layout_width="fill_parent"
android:layout_height="60dip"
android:gravity="center"></TextView>
</LinearLayout>
Its because the your linear layout [ban_layout] is covering up your listview, as you have set it to align towards the bottom of the parent.
Quick Hacks,
Add an extra row and set its inside elements to invisible in your listview adapter
or
Add an bottom margin to your listview that compensates the footer
Your best solution would be to rework the parent relativelayout and set up a linearlayouts with weights
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.