I have requirement of adding button behind single image. My main.xml is mentioned below. I am trying to create button3 for abcimage as shown below. I want this button at left center. How it can be done?
<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="#android:color/black">
<TableLayout
android:id="#+id/TableLayout01"
android:stretchColumns="*"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<TableRow
android:id="#+id/TableRow01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_gravity="center_vertical|center_horizontal">
<ImageView
android:id="#+id/ImageView2_Left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:src="#drawable/abcimage"></ImageView>
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="buyabc"
/>
</TableRow>
</TableLayout>
</LinearLayout>
Try this layout:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/ImageView2_Left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/abcimage" >
</ImageView>
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="buyabc" />
</RelativeLayout>
Use a FrameLayout which contains your image and your button:
<FrameLayout
android:id="#+id/TableRow01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal" >
<ImageView
android:id="#+id/ImageView2_Left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:src="#drawable/abcimage" >
</ImageView>
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="buyabc" />
</FrameLayout>
Related
How to customize FrameLayout, I have to make screen like this:
and i have made this :
So now i want to know, How can i achieve above Layout
How to show icon on top, like in above screen (Path)
How to place text above circles, like in above screen (Dark Text: Remember Life) (Light Text: Instantly ....)
How to place buttons below circles, like in above screen (Register & Login)
Here is my XML, in which i am using FrameLayout, see below:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.indianic.viewflipperdemo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.indianic.viewflipperdemo.widget.ViewFlow
android:id="#+id/viewflow"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:sidebuffer="3" >
</com.indianic.viewflipperdemo.widget.ViewFlow>
<com.indianic.viewflipperdemo.widget.CircleFlowIndicator
android:id="#+id/viewflowindic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:padding="10dip"
android:layout_marginBottom="10dip"
app:inactiveType="stroke" />
</FrameLayout>
Finally, I achieved my target, I used both the Layouts [Relative Layout and Linear Layout] to organize widgets, see complete XML :
circle_layout.xml:-
<?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/com.indianic.viewflipperdemo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.indianic.viewflipperdemo.widget.ViewFlow
android:id="#+id/viewflow"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:sidebuffer="3" >
</com.indianic.viewflipperdemo.widget.ViewFlow>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView2"
android:layout_centerHorizontal="true"
android:text="Remember Life"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/viewflowindic"
android:layout_centerHorizontal="true"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:padding="5dp"
android:text="Instantly search memories of friends, season, birthdays, and more"
android:textAppearance="?android:attr/textAppearanceSmall" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="10dp" >
<Button
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:layout_weight="1"
android:text="Register"
android:textColor="#000000" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="1"
android:text="Login"
android:textColor="#000000" />
</LinearLayout>
<com.indianic.viewflipperdemo.widget.CircleFlowIndicator
android:id="#+id/viewflowindic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout1"
android:layout_centerHorizontal="true"
android:padding="20dp"
app:inactiveType="stroke" />
</RelativeLayout>
And look at this awesome screenshot:
Use RelativeLayout instead FrameLayout. You will be more free with elements positions.
Relative Layout
Something like this you can do it
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.indianic.viewflipperdemo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.indianic.viewflipperdemo.widget.ViewFlow
android:id="#+id/viewflow"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:sidebuffer="3" />
<View
android:id="#+id/center"
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/button_register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/center"
android:padding="10dp"/>
<Button
android:id="#+id/button_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/center"
android:padding="10dp"/>
<com.indianic.viewflipperdemo.widget.ViewFlow
android:id="#+id/viewflowindic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button_register"
android:layout_gravity="bottom|center_horizontal"
android:padding="10dip"
android:layout_marginBottom="10dip"
app:inactiveType="stroke" />
<TextView
android:id="#+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/viewflowindic"
android:layout_centerHorizontal="true"
android:text="description"/>
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/description"
android:layout_centerHorizontal="true"
android:text="title"/>
</RelativeLayout>
btw use match_parent instead fill_parent.
Use RelativeLayout to organize views. For implementing view pager indicator try this link
https://github.com/JakeWharton/Android-ViewPagerIndicator
Sample
<?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">
//You can put an image view or text view to show your app name
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Path"
android:id="#+id/title"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="74dp"/>
**// Try view pager indicator here.**
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:weightSum="2"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:id="#+id/">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register"
android:layout_weight="1"
android:id="#+id/button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_weight="1"
android:id="#+id/button2"/>
</LinearLayout>
</RelativeLayout>
I am developing an Android Application and I have an Activity that looks like this. I have a header and a footer that have fixed positions, and a ListView with clickable items in the middle. Below the ListView, I have a button.
It is working when I have a few items, but as I add more items, the button begins to disappear, like this.
When I have more items in that list that can be shown in the page, I have a scroll in the list. If I scroll down like this I can see all the items in the list, but the button is hidden.
I have had a lot of problems before trying to add a ListView inside a ScrollView, so I know it doesn't work. As I am new in Android development, perhaps my XML layout files are a bit confusing, but I have a parent LinearLayout with two RelativeLayouts inside, one for the header and one for the middle and footer. The XML is something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFFFFF">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/background"
android:gravity="center_vertical">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="#string/baseTitle"
android:textColor="#FFFFFF"
android:layout_centerVertical="true"
android:textSize="18dp"
android:textStyle="bold"/>
<Button
android:id="#+id/buttonHelp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="#drawable/button_help"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="fill_vertical">
<LinearLayout
android:id="#+id/buttonBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:background="#bdbdbd"
android:layout_alignParentBottom="true">
<RelativeLayout
android:id="#+id/bottomButtomBar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<Button
android:id="#+id/myGroups"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="#string/myGroups"
android:gravity="center"
android:textSize="13dp"
android:textColor="#000000"
android:background="#layout/button_meus_grupos"/>
<Button
android:id="#+id/createGroups"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:text="#string/createGroups"
android:gravity="center"
android:textSize="13dp"
android:textColor="#000000"
android:background="#layout/button_criar_grupos"/>
<Button
android:id="#+id/configurations"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="#string/configurations"
android:gravity="center"
android:textSize="13dp"
android:textColor="#000000"
android:background="#layout/button_configuracoes"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_above="#id/buttonBar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/listContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical"
>
<RelativeLayout
android:id="#+id/searchBarLayout"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:orientation="horizontal"
android:background="#ffffff"
android:gravity="center_vertical"
android:clickable="true"
>
<TextView
android:id="#+id/myGroupsLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/myGroups"
android:layout_centerInParent="true"
android:textColor="#bdbdbd"
android:textSize="16dp"
android:textStyle="bold"
/>
<ImageView
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_search" />
</RelativeLayout>
<View android:layout_height="2dip"
android:layout_width="wrap_content"
android:background="#cccccc"
/>
<ListView android:id="#+id/listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:cacheColorHint="#000000"
/>
<Button
android:id="#+id/buttonCreateGroup"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:background="#layout/button_confirm"
android:layout_gravity="center_horizontal"
android:text="#string/createOneGroup"
android:textColor="#FFFFFF"
android:textSize="22dp"
android:layout_marginTop="15dp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Does anyone have any tips on how can I keep the footer fixed, scroll down until the end of the list and then show the button? I want that it looks like the button is the last item at the List.
EDIT: Entire XML posted
The ListView and the Button should be in a RelativeLayout and in the Button you should set android:layout_below="#id/listview"
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cacheColorHint="#000000"
android:textColor="#000000" />
<Button
android:layout_below="#id/listview"
android:id="#+id/buttonCreateGroup"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dp"
android:layout_marginTop="15dp"
android:background="#layout/button_confirm"
android:text="#string/createOneGroup"
android:textColor="#FFFFFF"
android:textSize="22dp" />
</RelativeLayout>
Try it in the following manner:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout //Header
android:layout_alignParentTop="true">
</RelativeLayout>
<ListView
android:layout_below="#+id/header" />
<RelativeLayout //Button(footer)
android:layout_alignParentBottom="true"
android:layout_below="#+id/listView" >
</RelativeLayout>
</RelativeLayout>
The only way I could achieve the exact requirements I explained above was doing the following:
-In the XML file with the layout of the list items, I added a button with android:visibility="gone".
-In my custom ListView adapter, I always add an empty object in the last position. I simply add an object with a flag that shows it is the last in the list.
-In the method getView() that I override in the custom Adapter, I check if the object in the current position has the flag indicating that it is the last in the list. If so, I set the button visibility to VISIBLE, otherwise I fill the other components.
If anyone is facing the same problem and needs some sample code from my solution just ask here.
Try this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="baseTitle"
android:textColor="#FFFFFF"
android:textSize="18dp"
android:textStyle="bold" />
<Button
android:id="#+id/buttonHelp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill_vertical"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/buttonBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/bottomButtomBar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<Button
android:id="#+id/myGroups"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:gravity="center"
android:text="myGroups"
android:textColor="#000000"
android:textSize="13dp" />
<Button
android:id="#+id/createGroups"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:gravity="center"
android:text="createGroups"
android:textColor="#000000"
android:textSize="13dp" />
<Button
android:id="#+id/configurations"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:gravity="center"
android:text="configurations"
android:textColor="#000000"
android:textSize="13dp" >
</Button>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/buttonBar"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/listContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/searchBarLayout"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:clickable="true"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/myGroupsLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="myGroups"
android:textColor="#bdbdbd"
android:textSize="16dp"
android:textStyle="bold" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp" >
</ImageView>
</RelativeLayout>
<ScrollView
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="280dip"
android:layout_margin="7dip"
android:scrollbars="none" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="#+id/listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cacheColorHint="#000000"
android:textColor="#000000" />
<Button
android:id="#+id/buttonCreateGroup"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dp"
android:layout_marginTop="15dp"
android:text="createOneGroup"
android:textColor="#FFFFFF"
android:textSize="22dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
I'm doing an android app and I want to separate layout in 3 parts like this:
but now the button is over the second listview but on the bottom of the screen, I don't know why.
I don't know if I have to use relativeLayout or linearLayout to including the listviews, and text are inside this or outside of relativelayout/linearLayout, and the last button what?
this is my code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:id="#+id/imageSelected"
android:text="#string/imgSelected"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginBottom="3dip"/>
<LinearLayout
android:id="#+id/linearLayoutImagenes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_below="#+id/imageSelected" >
<ListView
android:id="#+id/listaFusionPhotos"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout >
<TextView android:id="#+id/nameSelected"
android:text="#string/namSelected"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_below="#+id/linearLayoutImagenes"
android:layout_marginBottom="3dip"/>
<LinearLayout
android:id="#+id/linearLayoutNombres"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_below="#+id/nameSelected"
>
<ListView
android:id="#+id/listaFusionNombres"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout >
<Button
android:id="#+id/fusion"
android:layout_width="160dip"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayoutNombres"
android:layout_marginTop="3dip"
android:text="Fusionar"
android:onClick="Mostrar_Registrados"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
Try this. this looks like exactly same of the picture.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="11" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_weight="1"/>
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="4">
</ListView>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ListView
android:id="#+id/listView2"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="4">
</ListView>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayoutNombres"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_below="#+id/nameSelected"
android:layout_above="#+id/fusion" // "line added"
>
<Button
android:id="#+id/fusion"
android:layout_width="160dip"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayoutNombres" --> "remove this line"
android:layout_marginTop="3dip"
android:text="Fusionar"
android:onClick="Mostrar_Registrados"
android:layout_alignParentBottom="true"/>
I'm trying to put the buttonbar I've created on the bottom of each screen. I've succeeded for the first screen fairly easy.
Now I've tried to put it other screens, but it seems that it can't stick to the bottom of the screen. When I look in the hiearchyviewer, it looks like the RelativeLayout that's wrapped araound my layout and buttonbar, isn't filling the whole screen, though, its height is set to fill parent.
Can anyone help me by pointing out where I'm going wrong?
This is the XML I use:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<TableLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:padding="5pt" android:id="#+id/table"
android:stretchColumns="1">
<TableRow>
<TextView android:text="#string/Arbeiderbediende"
android:id="#+id/txtArbeiderBediende" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow android:gravity="center">
<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal"
android:id="#+id/group1">
<RadioButton style="#style/RadioButton"
android:layout_width="wrap_content" android:id="#+id/rbArbeider"
android:text="#string/Arbeider" android:layout_height="wrap_content"
android:paddingLeft="18pt" />
<RadioButton style="#style/RadioButton"
android:layout_width="wrap_content" android:id="#+id/rbBediende"
android:text="#string/Bediende" android:layout_height="wrap_content"
android:layout_marginLeft="20pt" android:paddingLeft="18pt" />
</RadioGroup>
</TableRow>
<TableRow android:gravity="center" android:paddingTop="5dip">
<TextView android:text="#string/OverzichtFuncties"
android:id="#+id/txtFuncties" android:layout_width="0dip"
android:layout_weight="1" android:layout_height="wrap_content" />
<Spinner android:layout_height="wrap_content" style="Spinner"
android:layout_width="0dip" android:layout_weight="2"
android:id="#+id/cmbFuncties" />
</TableRow>
<TableRow android:gravity="center" android:paddingTop="5dip">
<TextView android:text="#string/Regio" android:id="#+id/txtRegio"
android:layout_width="0dip" android:layout_weight="1"
android:layout_height="wrap_content" />
<Spinner android:layout_height="wrap_content"
android:layout_width="0dip" android:layout_weight="2" android:id="#+id/cmbRegio" />
</TableRow>
<TableRow android:gravity="center" android:paddingTop="5dip">
<TextView android:text="#string/Opleiding" android:id="#+id/txtOpleidingsniveau"
android:layout_width="0dip" android:layout_weight="1"
android:layout_height="wrap_content" />
<Spinner android:layout_height="wrap_content"
android:layout_width="0dip" android:layout_weight="2"
android:id="#+id/cmbOpleidingsniveau" />
</TableRow>
<Button android:text="#string/VindJobButton" android:id="#+id/btnFindJob"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginTop="10dip" />
</TableLayout>
<stage.accent.Toolbar android:layout_width="fill_parent"
android:layout_height="70dip" android:layout_alignParentBottom="true"
android:layout_below="#+id/table" />
</RelativeLayout>
This is the result I achieved and the result I want to get
In case you want your buttonbar to be always visible at the bottom of the screen and not scroll with the content, you might want to switch your RelativeLayout and ScrollView tags, and move your buttonbar to be the first child of your RelativeLayout, the ScrollView to be the second:
<?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">
<stage.accent.Toolbar android:id="id/buttonBar" android:layout_width="fill_parent"
android:layout_height="70dip" android:layout_alignParentBottom="true" />
<ScrollView android:layout_above="#+id/buttonBar"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TableLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:padding="5pt" android:id="#+id/table"
android:stretchColumns="1">
<TableRow>
<TextView android:text="#string/Arbeiderbediende"
android:id="#+id/txtArbeiderBediende" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow android:gravity="center">
<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal"
android:id="#+id/group1">
<RadioButton style="#style/RadioButton"
android:layout_width="wrap_content" android:id="#+id/rbArbeider"
android:text="#string/Arbeider" android:layout_height="wrap_content"
android:paddingLeft="18pt" />
<RadioButton style="#style/RadioButton"
android:layout_width="wrap_content" android:id="#+id/rbBediende"
android:text="#string/Bediende" android:layout_height="wrap_content"
android:layout_marginLeft="20pt" android:paddingLeft="18pt" />
</RadioGroup>
</TableRow>
<TableRow android:gravity="center" android:paddingTop="5dip">
<TextView android:text="#string/OverzichtFuncties"
android:id="#+id/txtFuncties" android:layout_width="0dip"
android:layout_weight="1" android:layout_height="wrap_content" />
<Spinner android:layout_height="wrap_content" style="Spinner"
android:layout_width="0dip" android:layout_weight="2"
android:id="#+id/cmbFuncties" />
</TableRow>
<TableRow android:gravity="center" android:paddingTop="5dip">
<TextView android:text="#string/Regio" android:id="#+id/txtRegio"
android:layout_width="0dip" android:layout_weight="1"
android:layout_height="wrap_content" />
<Spinner android:layout_height="wrap_content"
android:layout_width="0dip" android:layout_weight="2" android:id="#+id/cmbRegio" />
</TableRow>
<TableRow android:gravity="center" android:paddingTop="5dip">
<TextView android:text="#string/Opleiding" android:id="#+id/txtOpleidingsniveau"
android:layout_width="0dip" android:layout_weight="1"
android:layout_height="wrap_content" />
<Spinner android:layout_height="wrap_content"
android:layout_width="0dip" android:layout_weight="2"
android:id="#+id/cmbOpleidingsniveau" />
</TableRow>
<Button android:text="#string/VindJobButton" android:id="#+id/btnFindJob"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginTop="10dip" />
</TableLayout>
</ScrollView>
</RelativeLayout>
This way you'll be able to achieve what you want:
and
The button bar will be always at the bottom of your screen.
And by scrolling the content, you'll be able to see the last bit of it too, it won't be hidden behind the buttonbar:
I still suggests dont use ScrollView here is an example how you can show the ButtonBar at the bottom
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/headerlayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
>
<Button android:id="#+id/amap_back_btn" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" android:text="Back">
</Button>
<TextView android:id="#+id/amap_txt"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="" android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
</TextView>
<ImageButton android:id="#+id/amap_action_btn"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="#drawable/icon_menu_action"
android:layout_alignParentTop="true" android:layout_alignParentRight="true">
</ImageButton>
</RelativeLayout>
//What ever widgets you wants to add
<LinearLayout
android:id="#+id/bottomlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal"
>
<ImageButton android:id="#+id/map_refresh_btn"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="#drawable/icon_refresh"
android:gravity="center"
>
</ImageButton>
<Button android:id="#+id/map_log_btn" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Log"
android:gravity="center">
</Button>
<Button android:id="#+id/map_map_btn" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Map"
android:gravity="center"
>
</Button>
</LinearLayout>
</RelativeLayout>
that is all this is the most robust solution.
If you find it useful dont forget to mark it as an answer.
Please take one main linear layout
above scroll view and after ending
scroll view please set your bottom
bar..
It would be also my suggetion.
LinearLayout is the main view.
Within it
Another LinearLayout (layout_height=0dp and layout_weight = 1) *ll_container*
and you tabbar
Within *ll_container* place
a scrollview (layout_height=0dp and layout_weight = 1) with tablelayout
and the button
Probably for explanation. With layout_height=0dp and layout_weight = 1 you give your layouts the whole free place remaining after placing your tabbar and then after placing your button
UPD
<?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:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<ScrollView android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TableLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:padding="5pt" android:id="#+id/table"
android:stretchColumns="1">
<TableRow>
<TextView android:text="#string/Arbeiderbediende"
android:id="#+id/txtArbeiderBediende" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow android:gravity="center">
<RadioGroup android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal"
android:id="#+id/group1">
<RadioButton style="#style/RadioButton"
android:layout_width="wrap_content" android:id="#+id/rbArbeider"
android:text="#string/Arbeider" android:layout_height="wrap_content"
android:paddingLeft="18pt" />
<RadioButton style="#style/RadioButton"
android:layout_width="wrap_content" android:id="#+id/rbBediende"
android:text="#string/Bediende" android:layout_height="wrap_content"
android:layout_marginLeft="20pt" android:paddingLeft="18pt" />
</RadioGroup>
</TableRow>
<TableRow android:gravity="center" android:paddingTop="5dip">
<TextView android:text="#string/OverzichtFuncties"
android:id="#+id/txtFuncties" android:layout_width="0dip"
android:layout_weight="1" android:layout_height="wrap_content" />
<Spinner android:layout_height="wrap_content" style="Spinner"
android:layout_width="0dip" android:layout_weight="2"
android:id="#+id/cmbFuncties" />
</TableRow>
<TableRow android:gravity="center" android:paddingTop="5dip">
<TextView android:text="#string/Regio" android:id="#+id/txtRegio"
android:layout_width="0dip" android:layout_weight="1"
android:layout_height="wrap_content" />
<Spinner android:layout_height="wrap_content"
android:layout_width="0dip" android:layout_weight="2" android:id="#+id/cmbRegio" />
</TableRow>
<TableRow android:gravity="center" android:paddingTop="5dip">
<TextView android:text="#string/Opleiding" android:id="#+id/txtOpleidingsniveau"
android:layout_width="0dip" android:layout_weight="1"
android:layout_height="wrap_content" />
<Spinner android:layout_height="wrap_content"
android:layout_width="0dip" android:layout_weight="2"
android:id="#+id/cmbOpleidingsniveau" />
</TableRow>
</TableLayout>
</ScrollView>
<Button android:text="#string/VindJobButton" android:id="#+id/btnFindJob"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginTop="10dip" />
</LinearLayout>
<stage.accent.Toolbar android:layout_width="fill_parent"
android:layout_height="70dip" android:layout_alignParentBottom="true"
android:layout_below="#+id/table" />
</LinearLayout>
what ever I try it always ends up so the second checkbox in a row doesn't show, and I don't know how to put admob wedget on the bottom of the screen
This is what I'm aiming for, thanks ahead of time:
Try this...the trick is to use relative layout for the outermost layout and nest some linear layouts to get the check boxes to align
<?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">
<LinearLayout android:id="#+id/top_row" android:layout_alignParentTop="true" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_above="#+id/bottom_row">
<EditText android:id="#+id/edit_text1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="edit text"></EditText>
<LinearLayout android:id="#+id/check_box_holder" android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="fill_parent">
<LinearLayout android:id="#+id/check_box_left_col" android:orientation="vertical" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1">
<CheckBox android:id="#+id/CheckBox01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentLeft="true" android:text="CheckBox01"></CheckBox>
<CheckBox android:id="#+id/CheckBox02" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentLeft="true" android:text="CheckBox02"></CheckBox>
</LinearLayout>
<LinearLayout android:id="#+id/check_box_right_col" android:orientation="vertical" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1">
<CheckBox android:id="#+id/CheckBox03" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentLeft="true" android:text="CheckBox03"></CheckBox>
<CheckBox android:id="#+id/CheckBox04" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentLeft="true" android:text="CheckBox04"></CheckBox>
</LinearLayout>
</LinearLayout>
<Button android:id="#+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="button1"> </Button>
<EditText android:id="#+id/edit_text2" android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="edit text2"></EditText>
<Button android:id="#+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="button2"> </Button>
</LinearLayout>
<LinearLayout android:id="#+id/bottom_row" android:layout_alignParentBottom="true" android:orientation="horizontal" android:layout_width="fill_parent" android:gravity="center" android:layout_height="wrap_content" android:background="#88ffffff">
<com.admob.android.ads.AdView
android:id="#+id/ad_block"
android:layout_margin="1px" android:layout_width="350dip" android:layout_gravity="center" android:layout_height="58dip"/>
</LinearLayout>
</RelativeLayout>