I have a button and a expand list above this button , when the list is expanded the button below it disappears . how to make this button in fixed location?
<?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">
<include layout="#layout/ads_bar" ></include>
<TextView
android:text="Level 1:"
android:textSize="20dp"
android:id="#+id/TextView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></TextView>
<TextView
android:text="lorem ispum something about this level ..... :)"
android:textSize="16dp"
android:id="#+id/TextView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></TextView>
<ExpandableListView
android:id="#+id/listView"
android:scrollbars="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></ExpandableListView>
<include
android:layout_alignParentBottom="true"
layout="#layout/quick_links_bar"></include>
</LinearLayout>
where quick_links_bar represents button !
To acheve button aligned to the bottom it's better to use layout_weight attribute of the linear layout.
Simple example:
<LinearLayout>
<TextView layout_weight=1/>
<Button layout_height="wrap_content"/>
<LinearLayout>
This is better than using RElative layout because if using one you will have the bottom of your text cut off by the button, but in this case it will not happen.
Sounds like you want the quick_links_bar layout to always stay at the bottom? You'll need to use RelativeLayout for that.
Wrap your whole layout in a RelativeLayout and move your quick links bar layout outside of the LinearLayout and set the property android:layout_alignParentBottom="true" on it. For this next bit, you'll need to assign an id to your quick links bar. On your LinearLayout, set the property android:layout_above="#id/quicklinksbarid". Make sure your quick links bar include statement is above the LinearLayout.
Related
So i`m coding this custom listView Adapter. The adapter AXML looks like this:
The problem is that when i compile and run in emulator, the ListView item turns into this :
Can anyone help me figure out what is happening? Maybe help me fix it?. If you need any code let me know.
UPDATE: AXML file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:minWidth="25px"
android:minHeight="25px">
<TextView
android:text="ABC 232"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/shopName"
android:textColor="#3c3c3c"
android:textSize="22dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout2"
android:weightSum="1">
<TextView
android:text="~800m away"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/distance"
android:layout_marginLeft="0.0dp"
android:textColor="#3c3c3c"
android:layout_weight="0.5"/>
<TextView
android:text="Total: 12.45 RON"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/total"
android:layout_gravity="right"
android:layout_marginLeft="22.0dp"
android:textColor="#3c3c3c"
android:layout_weight="0.5"/>
</LinearLayout>
</LinearLayout>
Please change all the text views width and height attribute to wrap_content. Specially for text view for shopName.
You can also remove linearLayout1, linearLayout3 and linearLayout4. Since they added noting important to your view.
You do not need to encapsulate each TextView in a LinearLayout. If you desire padding around the font, the TextView has padding attributes that will achieve the same effect in a cleaner manner.
If you clean up the code in this way, the issue with views not appearing may appear clearer.
It could be much simpler, use relative layout and align all three text one another.
Steps to design:
1) Take Parent Relative layout and make it centre vertical and horizontal
2) Place text1 and make align top of parent and give margin or padding from left
3) Place text2 below of text1 and give padding or margin from top.
4) Place text3 toRight of text1 or text2 or make make it centre vertical and horizontal of parent or you give margin left. it is your choice which once you choose.
Let me if you want more help. :)GlbMP
I have no idea on how to achieve this layout:
So basically I want a title bar, bellow that I want a listview, while anchored to the bottom I want a button in the right side of the screen.
Right now I am trying with this code (unsuccessfully)
<?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" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView
android:layout_width="match_parent"
android:layout_height="436dp"
android:id="#+id/listView"
android:layout_gravity="right" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:id="#+id/button_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="ok"
android:layout_weight="0.45" />
</LinearLayout>
</LinearLayout>
By using this layout, my listview does not resize when changing from portrait to landscape so my bottom button goes out of screen. Also the bottom button is not aligned to the right side.
Any idea on how to achieve this?
So I need 2 "bars" one anchored to the top, and one anchored to the bottom. On the top "bar" I want a TextView, and on the bottom "bar" I want a button aligned to the right.
And I want the listView to fill the space between the 2 bars.
So there may be empty space in the middle, when listview has just 1-2-3 items (just like in the picture).
Can this be done?
Please advise...
Change your top layout to a relatuve layout, then place the button outside your linearlayout and inside your relative layout. Then set gravity layout_gravity to bottom||right
U can also drag t where u want it in the visual part of the xml layout
Change your top layout to a relatuve layout, then place the button outside your linearlayout and inside your relative layout. Then set gravity of the button tolayout_gravity to bottom||right
U can also drag t where u want it in the visual part of the xml layout
I have the following layout...
<?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"
android:background="#drawable/bg_generic_portrait">
<ListView android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/issue_list_item_background_normal"
android:listSelector="#drawable/issue_background_selector"
android:divider="#drawable/separator"
>
</ListView>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:id="#+id/preloader"
style="#android:style/Widget.ProgressBar.Large"/>
<TextView android:id="#android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF0000"/>
</LinearLayout>
And it looks like this...http://i.stack.imgur.com/Ra5c6.png
I want the preloader to be centered vertically too, what is wrong?
Somehow the layout_gravity does not work well.
What you need to do is nest the progress_bar in a linear_layout and set the gravity of that layout to center, like this:
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/preloader"
style="#android:style/Widget.ProgressBar.Large"/>
</LinearLayout>
I do not suggest setting the gravity to the topmost linear layout because you could have funny things happening if you change the list or add something.
thats because you are using a LinearLayout, I suggest that you use a RelativeLayout
and have the attibute center using layout_centerVertical like this:
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:id="#+id/preloader"
style="#android:style/Widget.ProgressBar.Large"/>
There seems some problem with what you are trying to do. ListView on top of progress bar in your layout can have a variable height depending on its contents. So, it's not possible to ensure progress bar stays in center of screen using linear layout.
You may want to look at ProgressDialog class that will show a progress dialog while you load data into list in background.
Alternatively, you can make ProgressBar and ListView overlap by using RelativeLayout as top level layout and specify android:layout_centerInParent="true" attribute for ProgressBar
Set android:gravity="center" in your parent LinearLayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
I don't know how much space is your Listview taking, but you might want to use a <RelativeLayout> instead of <LinearLayout> if you want to really define where you want x item.
I am attempting to make a ListView inside a table consume all of the available vertical space minus the space needed for an EditText control.
I have set every attribute I can think of here to make it work:
<?xml version="1.0" encoding="utf-8"?>
<TableRow android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF0000">
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#+id/conversation"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/>
</ScrollView>
</TableRow>
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00FF00">
<EditText android:id="#+id/messagetext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text|textAutoCorrect|textMultiLine|textImeMultiLine"
android:imeOptions="actionDone"/>
</TableRow>
I must be missing something, as the result is a fully filled horizontal, but both the ListView and EditText appear to be behaving as if their attributes were wrap_content.
Is there a particular reason you're using a TableLayout? I'm not very familiar with using them yet, but what you're trying to accomplish is simple with a RelativeLayout. Also, you don't need to place the ListView within a ScrollView, the ListView handles scrolling on its own. Here is an example of how you could accomplish this using a RelativeLayout:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:id="#+id/message_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00FF00"
android:inputType="text|textAutoCorrect|textMultiLine|textImeMultiLine"
android:imeOptions="actionDone"
android:alignParentBottom="true"
/>
<ListView
android:id="#+id/conversation"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF0000"
android:layout_above="#id/message_text"
/>
</RelativeLayout>
This way, you first define the EditText to take up a certain amount of space (wrap_content, in this instance). Then, you define the ListView to fill the remaining space with fill_parent. Adding android:layout_above="#id/message_text" aligns the bottom edge of the ListView with the top edge of the EditText view.
I appear to have been missing an attribute android:layout_weight on the top TableRow. Evidently, anything over 2 makes it consume the rest of the vertical real estate. Can anybody explain why the special treatment for TableRows?
Don't use ListView inside of ScrollView, because ListView manages it's own vertical scrolling. Doing so will kill all optimization's done by the ListView
And don't anwser to your own posts. Rather edit your initial questions or add an comment.
I am using following code to display button at the bottom of activity.
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
>
<Button android:id="#+id/btnGetMoreResults"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Get more"
/>
</RelativeLayout>
and listview above it. when i display more data in listview this button pannel is moved down.can any one guide me how can i fix it at the bottom of activity?
any help would be appreciated.
The answer selected as correct is faulty, the button will hide the lower part of the list view. The correct way is to declare the button first and position the list above the button.
<Button android:id="#+id/btnGetMoreResults"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Get more"
android:layout_alignParentBottom="true"/>
<ListView
...
android:layout_above="#id/btnGetMoreResults"/>
The android:layout_alignParentBottom attribute has to be declared in an element of the RelativeLayout not in the RelativeLayout himself (unless there is another RelativeLayout as a parent).
You should do something like this, with the ListView inside the RelativeLayout also :
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<ListView ...>
<Button android:id="#+id/btnGetMoreResults"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Get more"
android:layout_alignParentBottom="true" />
</RelativeLayout>
If you had, for example, all the scrollable elements in a ScrollView, you should do like the following:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="#style/rootElement"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- texts, buttons, images and anything that you want to scroll -->
</ScrollView>
<LinearLayout
android:orientation="vertical"
style="#style/footer"
android:id="#+id/footer"
android:layout_alignParentBottom="true"
>
</LinearLayout>
</RelativeLayout>
Note that if you want the footer to be fixed, then you shouldn't put it in the ScrollView, where the scrollable content will be placed. Make it child of RelativeLayout and set layout_alignParentBottom to true. Maybe you'll need to add a padding at the bottom of the ScrollView in this case (so that the last element do not get hidden by the footer).
The idea is similar for elements other than ScrollView