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.
Related
I have a ProgressBar in a ScrollView, and I'd like it to stay centered vertically despite the user scrolling down or up. However, I'm not sure how to accomplish this.
Here's the code that I have, simple as it is. I have an indeterminate ProgressBar:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ocr_scroll_view"
android:layout_width="match_parent"
android:layout_height="fill_parent">
<RelativeLayout android:id="#+id/image_holder"
android:layout_gravity="end"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView android:id="#+id/image"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ProgressBar android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:visibility="gone"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
And I call it as such:
spinningProgressBar = (ProgressBar)findViewById(R.id.progressBar1);
spinningProgressBar.setIndeterminate(true);
spinningProgressBar.setVisibility(View.GONE);
Setting its visibility at the appropriate times.
All suggestions very much appreciated.
You need the ScrollView to be at same level as ProgressDialog in your Layout.
Here it is in concept:
<RelativeLayout>
<ProgressDialog>
<ScrollView>
<RelativeLayout>
Put it outside of the ScrollView. Just have the ScrollView and the ProgressBar overlap.
You can read about how to overlap views here: Overlapping Views in Android
There's a couple of ways to do it, ranging from GridLayouts to RelativeLayouts and then programatic ways to do it.
you can insert this into the scrollview tag
android:fillViewport="true"
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.
My application containing different layouts.one of them is a linear layout.it's content is dynamically adding.i want to make this layout horizontally scrollable.for this i have put my layout in a scroll view.but still it s not scrolling...given below is my code
<LinearLayout android:id="#+id/scoreballparent_layout"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_above="#+id/score_layout">
<ScrollView android:layout_height="wrap_content"
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
>
<LinearLayout android:layout_width="fill_parent"
android:id="#+id/scoreball_layout"
android:layout_height="wrap_content"
android:isScrollContainer="true"
android:scrollbars="horizontal">
</LinearLayout>
</ScrollView>
</LinearLayout>
Use HorizontalScrollView instead
Also your layout will become scrollabe after its contect can't fit layout area.
Simply use this in xml
android:fadeScrollbars="true" may be it works for you
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.
friend's,
i have a problem in setting height of layout,i have three layout with seperate xml layout,
1.header.xml
it have an textview
2.main.xml have frmelayout with listview
3.content.xml
it have field to bind in framelayout listview.
i need to know how to increase the height of the header as much i need,
here my code for getting solution
Actually i'm facing problem here isi have gallery of menus in header ,whrn iplace this gallery view below header i'm getting it with hidded below half of the gallery,because the height of header can't being changed in any sense,
here the code for header.xml
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:background="#drawable/gradient_black"
android:layout_gravity="center_horizontal" android:layout_width="fill_parent"
android:orientation="horizontal">
<ImageView android:src="#drawable/image_button1" android:id="#+id/back"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true"/>
<TextView android:id="#+id/header_text1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_toRightOf="#+id/back"
android:textSize="20sp" android:textStyle="bold" android:textColor="#color/white"
android:layout_marginLeft="60dip" android:layout_centerVertical="true"
android:layout_centerHorizontal="true" android:ellipsize="end"
android:singleLine="true" />
<ImageView android:src="#drawable/image_button" android:id="#+id/share"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_toRightOf="#+id/header_text1" android:paddingTop="10dip"
android:paddingLeft="50dip" />
<Gallery android:id="#+id/gv" android:layout_width="fill_parent" android:paddingTop="0dip"
android:layout_height="fill_parent" android:spacing="15dip"
android:layout_below="#+id/back"
android:gravity="bottom" android:paddingBottom="0dip"/>
</RelativeLayout>
here the code for main.xml it have an FrameLayout have listview,have tab host and linearlayout at top
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="200dip" android:id="#+id/main_lay">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:id="#android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="100dip"
android:layout_marginTop="100dip">
<ListView android:id="#+id/content_listview"
android:layout_width="fill_parent" android:layout_height="340dip" />
</FrameLayout>
.
.
.
</LinearLayout>
----
</TabHost>
==================== code for list content field
it have linerlayout with three field to set on list...
===== here code for my activity
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.main); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.header);
. ;.---- help me get the clear view of gallery in header without hidding at bottom or simply how can i increase height of header layout.
As WarrenFaith said, we can't help you without the XML code. The basic answer with the informations you gave is layout_height but you can have set fill_parent and layout_weight to other fields and it would not be the same. Please provide some code
#MGSenthil: everybody was once new here. Simply work with and not against us :)
Back to topic: What do you mean with because the height of header can't being changed in any sense? Please clarify if you cant change the height because it didnt work or if you cant change it because it has to be this size?!
If you want to have this header with a specific size, you should consider to remove something of the content so it fits.
I never used a custom title, but you should check if its not better to request NO_TITLE and simply add your header to the main.xml layout? You should be able to increase the height of your header that way.