display button in relativeout below relativelayout - android

My problem is i cannot show the two button in my layout under the listview. Below i have a listview within a relativelayout. i have a second relativelayout that contains 2 button. the buttons seem to show on top of the list whereas i would like them below the list.
how can i do this?
i've tried setting the 'android:layout_below' in the second RRlayout giving the first layout as the anchor.
Thanks in advance.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="#+id/textviewcarername"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/blue_alpha_background"
android:gravity="center"
android:text="Rota "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/carerdetailsfragrellayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textviewcarername"
android:background="#drawable/textviewbg"
android:padding="10dp" >
<ListView
android:id="#+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cacheColorHint="#0000"
android:divider="#700000ff"
android:dividerHeight="4px" >
</ListView>
</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<Button
android:id="#+id/buttonprevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Previous" />
<Button
android:id="#+id/buttonnext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Next" />
</RelativeLayout>
</RelativeLayout>

This layout should do the job
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!-- Header -->
<TextView
android:id="#+id/textviewcarername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/blue_alpha_background"
android:gravity="center"
android:text="Rota "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
/>
<!-- Bottom Layout (Footer) -->
<RelativeLayout
android:id="#+id/rlFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<Button
android:id="#+id/buttonprevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Previous"
/>
<Button
android:id="#+id/buttonnext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Next"
/>
</RelativeLayout>
<!-- ListView -->
<RelativeLayout
android:id="#+id/carerdetailsfragrellayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/textviewcarername"
android:layout_above="#id/rlFooter"
android:background="#drawable/textviewbg"
android:padding="10dp"
>
<ListView
android:id="#+id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#0000"
android:divider="#700000ff"
android:dividerHeight="4px"
/>
</RelativeLayout>
</RelativeLayout>
Note that I moved the bottom layout BEFORE the one containing the ListView and assigned it an id, so it could be referred by the ListView container
I also removed the extra namespace definitions
[EDIT]
I now changed the ListView and its container wrap_content to match_parent, in order to fill the remaining space. The ListView should now fit perfectly (I forgot that particular)
[EDIT 2]
You might want to remove the RelativeLayout that encloses the ListView and add its attributes to the ListView itself, to help flattening your design - for performance increase (as little as it may be).

Try this..
<?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="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textviewcarername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Rota "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
<RelativeLayout
android:id="#+id/carerdetailsfragrellayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:padding="10dp" >
<ListView
android:id="#+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cacheColorHint="#0000"
android:divider="#700000ff"
android:dividerHeight="4px" >
</ListView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/buttonprevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Previous" />
<Button
android:id="#+id/buttonnext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Next" />
</RelativeLayout>
</LinearLayout>

Give an id to the RelativeLayout which contains Buttons as android:id="#+id/button_panel" and add the attribute android:layout_above="#+id/button_panel" in the RelativeLayout which contains ListView as below...
<TextView
android:id="#+id/textviewcarername"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/blue_alpha_background"
android:gravity="center"
android:text="Rota "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<RelativeLayout
android:id="#+id/carerdetailsfragrellayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textviewcarername"
android:background="#drawable/textviewbg"
android:layout_above="#+id/button_panel"
android:padding="10dp" >
<ListView
android:id="#+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cacheColorHint="#0000"
android:divider="#700000ff"
android:dividerHeight="4px" >
</ListView>
</RelativeLayout>
<RelativeLayout
android:id="#+id/button_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/buttonprevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Previous" />
<Button
android:id="#+id/buttonnext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Next" />
</RelativeLayout>

Related

Button is not displaying in layout in Android

I have made an Android activity. In this activity I have a ListView and a Button. I want to add the Button to the bottom of screen. I have tried so long but it's hidden from tabbar. My xml code is as below. Please help me.
code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.eps.blancatours.uc.Header
android:id="#+id/hdr_dest_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<RelativeLayout
android:id="#+id/rl_main_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/hdr_dest_list"
android:padding="10dp" >
<ListView
android:id="#+id/dest_List"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/btn_next" />
<Button
android:id="#+id/btn_next"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:background="#D41016"
android:text="#string/next"
android:textColor="#ffffff"
android:textSize="14dp" />
</RelativeLayout>
</RelativeLayout>
Make changes like below -
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity" >
<LinearLayout android:id="#+id/li"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<com.eps.blancatours.uc.Header
android:id="#+id/hdr_dest_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button1"
android:id="#+id/list"
android:padding="30dp"
/>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#68bdb6"
android:text="#string/Select" />
</RelativeLayout>
You did not close your main Relativelayout just close that layout button will appear below the listview
You didn't close your main RelativeLayout with </RelativeLayout>.
For me your code works, you just have to close your relative layout.
It does working here, all I added is just </RelativeLayout> tag before the parent tag.
and my text in place of the #String reference.
also Try changing android version when rendering layout.
Wrapping ListView and Button with nested RelativeLayout is redundant. You could set you XML like this:
<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" >
<com.eps.blancatours.uc.Header
android:id="#+id/hdr_dest_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<ListView
android:id="#+id/dest_List"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/hdr_dest_list"
android:layout_above="#+id/btn_next" />
<Button
android:id="#+id/btn_next"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp"
android:background="#D41016"
android:text="#string/next"
android:textColor="#ffffff"
android:textSize="14dp" />
</RelativeLayout>
Also use match_parent instead fill_parent
Add the below inside Button
android:layout_below="#id/list"
Add android:orientation="vertical" on your both RelativeLayouts as
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.eps.blancatours.uc.Header
android:id="#+id/hdr_dest_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<RelativeLayout
android:id="#+id/rl_main_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/hdr_dest_list"
android:padding="10dp"
android:orientation="vertical" >
<ListView
android:id="#+id/dest_List"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/btn_next" />
<Button
android:id="#+id/btn_next"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:background="#D41016"
android:text="#string/next"
android:textColor="#ffffff"
android:textSize="14dp" />
</RelativeLayout>
</RelativeLayout>
And don't forget to clear the project.

Listview and a button in the bottom of the screen

I've tried everything, and looked up everywhere..!
I'm trying to put a listview within a scrollview, and a button at the bottom of the screen fixed..
This is my 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="vertical" >
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/rlCommento" />
<RelativeLayout
android:id="#+id/rlCommento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" >
<EditText
android:id="#+id/etCCommento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="15"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="#+id/bCInviaCommento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/etCCommento"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_weight="85"
android:text="Commenta!" />
</RelativeLayout>
</RelativeLayout>
It seems working in the project, but when I try it on the emulator, it doesn't work!
Any advice ? Thanks!
This is what you have to do:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:text="Button" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button1"
android:layout_centerHorizontal="true" >
</ListView>
</RelativeLayout>
You can use LinearLayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<RelativeLayout
android:id="#+id/rlCommento"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
...
</RelativeLayout>
</LinearLayout>
First: Don't put list view inside scroll view
Second: make your top most parent width n height to match parent
Third: add a new layout at bottom and add button inside this layout, something like this, give layout some weight
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingBottom="7dp"
android:paddingTop="7dp" >
<Button
android:id="#+id/score_board"
android:layout_width="wrap_content"
android:layout_height="55dp"
android:layout_gravity="center"
android:layout_weight="1"
android:text="OK" />
</LinearLayout>
// Try this way,hope this will help you to solve your problem...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="5dp">
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"/>
<LinearLayout
android:id="#+id/rlCommento"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<EditText
android:id="#+id/etCCommento"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="#+id/bCInviaCommento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="Commenta!" />
</LinearLayout>
</LinearLayout>
To do that you have to LinearLayout vertical instead of RelativeLayout and set ListView weight=1 and layout_height=0dp.
This should work just as needed:
<?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" >
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<RelativeLayout
android:id="#+id/rlCommento"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/etCCommento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="15"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="#+id/bCInviaCommento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/etCCommento"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_weight="85"
android:text="Commenta!" />
</RelativeLayout>
Hope I understood your problem correctly. No need of keeping ListView inside scrollview. Just try following snippet. It will may for you.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="#+id/bCInviaCommento"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Commenta!"
android:layout_below="#id/list" />
</RelativeLayout?

XML Layout overlap

I am trying to create a certain layout, that consists of 2 parts a scrollview and a "footer" at the bottom, but always on top of the scrollview. Everything inside the scrollview must be visible (by scrolling).
This is my current code:
<?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"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/banner" />
<TextView
android:layout_width="fill_parent"
android:paddingTop="1dp"
android:layout_height="3px"
android:background="#DADADA" />
<RelativeLayout
android:id="#+id/InnerRelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Start Connecting" />
<Button
android:id="#+id/button01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button1"
android:layout_alignParentLeft="true"
android:text="First use" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Welcome to ADB Wireless!"
android:textSize="25sp" />
</RelativeLayout>
</LinearLayout>
But it gives an overlap on small screens & landscape mode. I would only like to have the 2 buttons to be inside the 'footer'. Thank you!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/button_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Next" />
<Button
android:id="#+id/button01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Previous" />
</LinearLayout>
<ScrollView
android:id="#+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/button_layout" >
</ScrollView>
</RelativeLayout>

How to show layout on the bottom of ListView

I have a layout xml like below:
<?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="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:maxWidth="71dip"
android:src="#drawable/logo_top" >
</ImageView>
<ImageView
android:id="#+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:adjustViewBounds="false"
android:clickable="true"
android:maxHeight="70dip"
android:src="#drawable/registeration_title" >
</ImageView>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" >
</TextView>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/linearframe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/informationFrame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal" >
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:src="#drawable/registeration_info1" />
<TextView
android:id="#+id/IDNumberTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="7dip"
android:layout_marginLeft="26dip"
android:text="TextView"
android:textColor="#drawable/textgreen" />
<TextView
android:id="#+id/EnableDateTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="7dip"
android:layout_marginLeft="140dip"
android:text="TextView"
android:textColor="#drawable/textgreen" />
</FrameLayout>
</LinearLayout>
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/linearframe"
android:text=" " />
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textView2"
android:layout_centerHorizontal="true"
android:src="#drawable/buy_in_60" />
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_alignLeft="#id/imageView5"
android:layout_alignRight="#id/imageView5"
android:layout_below="#id/imageView5" >
</ListView>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" " />
<FrameLayout
android:id="#+id/frameLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/listView1"
android:layout_centerHorizontal="true"
android:layout_marginLeft="79dp" >
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/registeration_info2" />
<TextView
android:id="#+id/VersionTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="48dip"
android:text="Version: 1.0"
android:textColor="#drawable/darkgreen" />
</FrameLayout>
<TextView
android:id="#+id/RevisionTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/frameLayout2"
android:layout_centerHorizontal="true"
android:layout_marginLeft="79dp"
android:text="Revision: 16"
android:textColor="#drawable/darkgreen" />
</RelativeLayout>
some layouts below the ListView in the xml will disappear on the screen
and I tried to put the ListView and other layouts below the ListView into a scrollView
but the ListView will shrink, it looks too small, so i remove the ScrollView,
how should i do to let them appear on the screen without ScrollView?
You need to set Weight to your layouts like this way..
like you can set ListView Weight is= 0.80 and Bottom View is = 0.20 make sure parent Linear layout Weight sum is = 1.
You can see this is my xml file having List View (80% screen) and bottom Bar layout for Google Ads (almost 20% screen).
<?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:weightSum="1">
<LinearLayout
android:id="#+id/layVrt"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_weight="0.72"
android:weightSum="1">
<ListView
android:layout_width="match_parent"
android:id="#+id/listViewGame"
android:textFilterEnabled="true"
android:layout_height="350dp"
android:layout_weight="0.73"></ListView>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:gravity="center"
android:layout_width="match_parent"
android:layout_weight="0.20"
android:layout_marginTop="5dp"
android:background="#drawable/rounded_corners_white"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:layout_height="50dp"
android:layout_marginBottom="3dp"
android:id="#+id/layoutAdMobList">
</LinearLayout>
</LinearLayout>
so this will be the output..
Or you can try something like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottom_bar" >
</ListView>
<LinearLayout
android:id="#+id/bottom_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/bottom_bar"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ToggleButton
android:id="#+id/slider_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#drawable/bottom_toggle_button" />
<ToggleButton
android:id="#+id/list_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#drawable/bottom_left_button" />
<ToggleButton
android:id="#+id/map_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/bottom_right_button" />
</LinearLayout>
</RelativeLayout>
Place everything inside a RelativeLayout and use android:layout_above="#+id/bottom_bar" on the ListView

How to add footer like view to a listview in android?

I have a list view, editText and button. editText and button are my footer to the listview. What is want is the footer to be positioned at the bottom of the screen and the listview to be scrollable above the footer. My layout is something like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:>
</ListView>
<EditText
android:id="#+id/txtType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/add" />
<Button
android:id="#+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:onClick="onClick"
android:text="Add" />
</RelativeLayout>
I have achieved above picture but my problem is that the listview scrolls below my footer. Footer is like floating over the listview. I want the listview to be scrollable above this footer only. help me
<?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">
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="#+id/bbar">
</ListView>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="#+id/bbar">
<EditText
android:id="#+id/txtType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/add" />
<Button
android:id="#+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:onClick="onClick"
android:text="Add" />
</RelativeLayout>
</RelativeLayout>
Give Editbox and button in another LinearLayout,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:>
</ListView>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center" >
<EditText
android:id="#+id/txtType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/add" />
<Button
android:id="#+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:onClick="onClick"
android:text="Add" />
</LinearLayout>
</RelativeLayout>
Thanks....
Wrap Editbox and button in another LinearLayout, . then use alignParentBottom=true property for the Linear Layout .
Just add this android:layout_above="#+id/txtType" to your ListView.
<?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" >
<ListView
android:id="#android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/txtType"
android:layout_alignParentTop="true"
android:="" >
</ListView>
<EditText
android:id="#+id/txtType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/add" />
<Button
android:id="#+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:onClick="onClick"
android:text="Add" />
</RelativeLayout>
check out this this is working for me
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:background="#drawable/login_page_bg"
android:layout_height="fill_parent"
>
<ListView
android:id="#android:id/list"
android:layout_above="#+id/footerlayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<RelativeLayout
android:id="#+id/footerlayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:onClick="onClickAddChild"
android:text="Add+"/>
</RelativeLayout>
</RelativeLayout>

Categories

Resources