Layout with list - android

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"

Related

Adding a button in the button right side of the screen

I have the following android layout that displays toe list views in the screen one in left side one the other to right side.
<?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="horizontal">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1" android:id="#+id/ListView01"/>
<ListView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="3" android:id="#+id/ListView02"/>
Now I want to add a button displayed it the bottom right side of the screen.
Can anyone help me about how I could do that?
first remove the linear layout,use relative layout.for button use the following command
android:layout_alignParentBottom="true" and android:layout_alignParentRight="true"
A possible solution should be: Add a RelativeLayout as root layout and put the button after the LinearLayout with properties layout_below and layout_right (LinearLayout as reference).
Try to use the following code
<?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="horizontal"
android:background="#ffffff"
>
<Button
android:id="#+id/click"
android:layout_width="100dip"
android:layout_height="60dip"
android:text="Click"
android:layout_alignParentRight="true"
/>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ListView02"
android:background="#00ff00"
android:layout_toLeftOf="#+id/click"
/>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ListView01"
android:background="#000000"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/ListView02"
/>
</RelativeLayout>
Thanks
Deepak

How do I place the text inside an EditText widget at the top?

I have the following xml for an edittext and button which take the whole screen. The only problem is I can't find a way to make the typed text in the edittext to be put at the top. Right now it's put in the centre of the editText.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#drawable/herinnering_background"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText
android:id="#+id/invoerTekst"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="#string/prompt_tekst" />
<Button
android:id="#+id/klaar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:text="#string/action_sla_op"
android:background="#drawable/main_button_over"
android:textColor="#ffffff"
android:layout_margin="5dip"
android:layout_below="#id/invoerTekst" />
</LinearLayout>
Add android:gravity="top" attribute to your EditText.
Use this, It will help you.
EditText
android:id="#+id/invoerTekst"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="#string/prompt_tekst"

Android - how to get ListView to line up underneath Text View

I am attempting to put a ListView beneath a Text View in an Android App. However, the first line of the ListView shows up on the same line as the TextView. How do I get this to move underneath?
Here is the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:id="#+id/android:question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/dummy_question" />
<ListView android:id="#+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/no_notes"/>
</LinearLayout>
I think at first look prob. is only that in linearlayout put
android:orientation=vertical
it will solve ur prob.
Try using a TableLayout. Example. Good luck.
I see two issues. First, as chirag mentioned, you need to set the ListView orientation. Second, a listView cannot 'wrap content' for height. What would it wrap to? One row, two? Basically, a listView has no idea how tall you want it to be. Try this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:id="#+id/android:question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/dummy_question" />
<ListView android:id="#+id/android:list"
android:layout_width="wrap_content"
android:layout_height="0px" android:layout_weight="1" />
<TextView android:id="#+id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/no_notes"/>
</LinearLayout>

Android : How to avoid header from scrolling in listview , android?

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

Problem when using more elements in the ListView

I have a ListView and a button in my view. Button is placed just below the listview. My listview contains 10 items. When I am running the application. I can't see the button inside the view. Because of 10 items i have to scroll the listview to see all items. If i use 4 items, I can see the button. Why it is happened?
Please help me.
Thank you..
I think you want button to be displayed always on the screen whatever maybe the size of the screen/list.
Just make your layouts to be AbsoluteLayouts as below
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pixels"
android:layout_y="50px"
android:layout_x="80px"
android:focusable="true">
</Button>
<ListView android:id="#+id/ListView01"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
</ListView>
</AbsoluteLayout>
& in you UI thread use bringToFront on that button as below
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
Button b= (Button) findViewById(R.id.button);
b.setText("Button");
b.bringToFront();
....
}
and you are done!
Sounds like you might not use layout correctly. Are you using a linear layout in the view? If so you might want to look at relative layout. Align your button to parentBottom and make you list align to parentTop and to above your button. That should make the list scroll and not expand.
check the width of your views, make sure it is set to wrap_contnet
You can modify your xml like this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<ListView android:layout_width="match_parent"
android:id="#+id/listVie"
android:layout_weight="0.80"
android:layout_height="0dp">
</ListView>
<Button
android:layout_width="fill_parent"
android:layout_weight="0.20"
android:layout_height="0dp"/>
</LinearLayout>
Look at the weight property:
android:weightSum="1"
android:layout_weight="0.80"
android:layout_weight="0.20"
They are making it :)
You shold use
android:weightSum="10"
android:layout_weight="8"
android:layout_weight="2"
I have a ListView and a button in my view. Button is placed just below the listview. My listview contains 10 items. When I am running the application. I can't see the button inside the view.
You can use relative layout something like this to achieve
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000">
<ListView
android:id="#+id/frg_product_inq_productSp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/btn_add"
android:layout_alignParentTop="true"
android:divider="#ffffff"
android:dividerHeight="0.5dp"
android:gravity="center" />
<Button
android:id="#+id/btn_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="ADD"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
And i.e your output will look like below for all devices

Categories

Resources