Bottom bar layout in android - android

This is my android xml source code for a map - bottom bar layout. I am displaying a huge map in the screen and i need a 30dp tall layout in the bottom of the screen to display a few tab like images. How do i push the horizontal linear layout to the bottom of the page ?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height=" what here ? "
android:layout_width="fill_parent"
android:orientation="vertical">
<com.google.android.maps.MapView
android:id="#+id/map_view"
Map goes here. Almost full screen. Exactly full - 30dp;
/>
<LinearLayout>
I want 3 images here. Bottom of the screen.
</LinearLayout>
</RelativeLayout>

Use android:layout_alignParentBottom="true" to set the linearlayout at the bottom of the parent for linearlayout and android:layout_above for mapview to set the mapview above the linearlayout.
Your code will be:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<LinearLayout android:layout_height="30dip"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:id="#+id/linearLayout1"
>
<!-- ... -->
</LinearLayout>
<com.google.android.maps.MapView
android:id="#+id/map_view"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_above="#+id/linearLayout1"
/>
</RelativeLayout>

<?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" >
<com.google.android.maps.MapView
android:id="#+id/map_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/rel_bottom" />
<RelativeLayout
android:id="#+id/rel_bottom"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:layout_height="30dp" >
<ImageView
android:id="#+id/img1"
android:layout_width="40dp"
android:layout_height="fill_parent" />
<ImageView
android:id="#+id/img2"
android:layout_width="40dp"
android:layout_height="fill_parent"
android:layout_toRightOf="#+id/img1" />
<ImageView
android:id="#+id/img3"
android:layout_width="40dp"
android:layout_height="fill_parent"
android:layout_toRightOf="#+id/img2" />
</RelativeLayout>
</RelativeLayout>

use the properties of the RelativeLayout, like android:layout_alignParentBottom and android:layout_above.
I would do something like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<LinearLayout
android:id="#+id/footer"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:width="fill_parent"
android:height="30dp">
add your images here
</LinearLayout>
<com.google.android.maps.MapView
android:id="#+id/map_view"
android:height="fill_parent"
android:width="fill_parent"
android:layout_alignParentTop="true"
android:layout_above="#id/footer"/>
</RelativeLayout>

Try the following layout. Using android:layout_alignParentBottom="true" won't be enough as the MapView with android:layout_height="fill_parent" will fill the whole screen and hide the LinearLayout. You must also add android:layout_above="#id/menu" so it won't hide it.
<?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" >
<com.google.android.maps.MapView
android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/menu"
android:apiKey="#string/google_maps_api_key"
android:clickable="true" />
<LinearLayout
android:id="#+id/menu"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_alignParentBottom="true" >
</LinearLayout>
</RelativeLayout>

Related

Android LinearLayout with Button and FrameLayout using the Maximum Height

I am trying to make a layout where there are a LinearLayout and inside it I want a FrameLayout and a button.
I want the button to use the bottom of the linearlayout and to use the maximum width and the enough height for the button, using wrap content.
The other component, the FrameLayout I want to use it the remaining part of the screen.
How can I do it?
Here it the layout so far..
<?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="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:onClick="snapIt"
android:text="#string/Capture" />
</LinearLayout>
Is not showing the button :s
Thanks alot in advance ;)
Better to work out with relative layout with button aligned to parent bottom and your frame layout above it occupying the rest space of the screen.Like this
<?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="match_parent" >
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/button_capture"/>
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="snapIt"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
use the following xml
<?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="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button_capture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="snapIt"
android:layout_alignParentBottom="true"
android:text="capture" />
<FrameLayout
android:id="#+id/camera_preview"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button_capture"
/>
</RelativeLayout>
i am just trying to make these layout, after compare my layout code and your layout code, i find a different code, there is in my code. Did you missing it or just move it away cause it useless from the layout code ?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<FrameLayout
android:id="#id/flayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello_world">
</FrameLayout>
</LinearLayout>

Two fragments in one layout but only one is shown

I am working on an android project and I am trying to make use of fragments but I am having an issue.
In my fragment activity I have a layout which contains two fragments. For some reason when I load the activity, I am only seeing the first fragment which is the query editor.
Below is the layout for the fragment activity
<?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:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<fragment android:name="com.BoardiesITSolutions.MysqlManager.QueryEditor"
android:id="#+id/fragment_queryEditor"
android:layout_width="fill_parent"
android:layout_height="100dp"/>
<fragment android:name="com.BoardiesITSolutions.MysqlManager.ResultViewer"
android:id="#+id/fragment_resultViewer"
android:layout_width="fill_parent"
android:layout_height="300dp" />
</LinearLayout>
</RelativeLayout>
Below is the layout for the query editor fragment
<?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"
android:background="#c1c1c1c1" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="QUERY EDITOR"/>
</LinearLayout>
Below is the layout for the result view fragment
<?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"
android:background="#000000">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="RESULT SET VIEW"/>
</LinearLayout>
For some reason only the query editor is being shown.
Although at the moment the query editor is set to 100dp and the result view is 300 dp I am only doing this as a test.
What I am actually wanting to do is to the query editor set to 100dp and the result view take up the rest of the space.
Thanks for any help you can provide
Change
<fragment android:name="com.BoardiesITSolutions.MysqlManager.QueryEditor"
android:id="#+id/fragment_queryEditor"
android:layout_width="fill_parent"
android:layout_height="100dp"/>
<fragment android:name="com.BoardiesITSolutions.MysqlManager.ResultViewer"
android:id="#+id/fragment_resultViewer"
android:layout_width="fill_parent"
android:layout_height="300dp" />
with
<fragment android:name="com.BoardiesITSolutions.MysqlManager.QueryEditor"
android:id="#+id/fragment_queryEditor"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="100dp"/>
<fragment android:name="com.BoardiesITSolutions.MysqlManager.ResultViewer"
android:id="#+id/fragment_resultViewer"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="300dp" />
this way your fragments will occupy the same space in the LinearLayout
Why do you have a LinearLayout inside a RelativeLayout?
This should do the thing:
<?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">
<fragment android:name="com.BoardiesITSolutions.MysqlManager.QueryEditor"
android:id="#+id/fragment_queryEditor"
android:layout_width="fill_parent"
android:layout_height="100dp"/>
<fragment android:name="com.BoardiesITSolutions.MysqlManager.ResultViewer"
android:id="#+id/fragment_resultViewer"
android:layout_below="#+id/fragment_queryEditor"
android:layout_width="fill_parent"
android:layout_height="300dp" />
</RelativeLayout>

layout_alignParentBottom not working as expected

I am trying to get a couple of buttons to attach to the bottom of the screen.
For some reason they are attaching themselves to the previous view:
As you can see the buttons are overwriting the previous view.
This is the layout I use:
<?xml version="1.0" encoding="utf-8" ?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:text_field_element="http://schemas.android.com/apk/res-auto"
xmlns:button_element="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:orientation="vertical"
>
<LinearLayout android:id="#+id/data_entry"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<com.applicat.meuchedet.views.TextFieldElement
android:id="#+id/dental_clinics_search_screen_clinic_type_selector"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
text_field_element:prompt="#string/dental_clinic_search_screen_dental_clinic_type_prompt"
text_field_element:initial_text="#string/dental_clinic_type_initial"
text_field_element:cursor_visible="false"
/>
<include
layout="#layout/separator_element"
/>
<com.applicat.meuchedet.views.LocationSelector
android:id="#+id/dental_clinics_location_selector"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<include
layout="#layout/separator_element"
/>
<com.applicat.meuchedet.views.TimeSelector
android:id="#+id/dental_clinics_time_selector"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<include
layout="#layout/separator_element"
/>
</LinearLayout>
<com.applicat.meuchedet.views.ButtonElement
android:id="#+id/dental_clinics_search_screen_search_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
button_element:margin_bottom="10"
/>
<com.applicat.meuchedet.views.ClearButtonElement
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/dental_clinics_search_screen_search_button"
android:layout_alignParentBottom="true"
button_element:margin_bottom="10"
/>
</RelativeLayout>
separator_element.xml
<?xml version="1.0" encoding="UTF-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:layout_marginBottom="15dip"
android:src="#drawable/form_separator"
>
</ImageView>
============================================================================
Edit:
So, it seems that the problem is caused by the fact that the view is put into a ScrollView. We need the ScrollView due to the possibility of small screens.
For some reason it sets the size wrong or something and puts the buttons just below the fields instead of at the very bottom.

set ImageView below a ScrollView

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF" >
<LinearLayout
android:layout_width="590dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
...
Can I place image as background in bottom Activity (window)? For instance, when scrolling ScrollView, image must be always bottom and visible.
Did you try using RelativeLayouts? Something like:
<RelativeLayout android:width="fill_parent"
android:height="fill_parent"
...>
<WhateverYouWantAtBottom android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
/>
<ScrollView android:layout_width="fill_parent"
android:layout_height="wrap_content">
<whateverYouWantScrollable android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</ScrollView>
</RelativeLayout>
At the bottom you could have an imageview with the image you wanted. No matter how long your content in the scrollview is, the imageview will not budge from the bottom as long as it has the alignParentBottom set as true.
EDIT: In the above code, the <whateverYouWantAtTheBottom> will be in the background as I declared it first. The foreground will be the contents of the scrollView as that was added last in the XML.
i tried this and its work for 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"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:layout_alignParentBottom="true"
/>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/imageView1" >
</ScrollView>
</RelativeLayout>

Great Issue with setting a button in landscape mode

I have an activity which is set up in the landscape mode and must remain this way(!So as an answer to my question don't tell me to set my activity in the PORTRAIT mode cause this is not a solution).
And I wanna put a button at the bottom of the screen like this:
http://i52.tinypic.com/30n9o5t.png
but I just can do it.All my attempts got me only this:
http://i53.tinypic.com/54acjs.png
Here is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
>
<SurfaceView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/surface_camera"
/>
<Button android:id="#+id/btnPhoto"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Take Photo !!"></Button>
</FrameLayout>
Don't forget my activity is in LANDSCAPE mode.
Thank you!
Using Image button instead.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
>
<SurfaceView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/surface_camera"
/>
<ImageButton android:id="#+id/btnPhoto"
android:layout_gravity="right"
android:layout_width="your_button_width"
android:layout_height="your_button_height"
android:background="#drawable/your_button_here">
</ImageButton>
</FrameLayout>
The trick is done using layout_weight which is telling the layout to use all free space available. So you are creating two layouts the second with fixed height and the tell the first to use all the free space. This solution will work in both cases Landscape and Portrait mode.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical"
android:layout_weight="1.0">
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="40dp">
<!-- place your buttons in this layout -->
</LinearLayout>
</LinearLayout>
UPDATE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical"
android:layout_weight="1.0">
</LinearLayout>
<LinearLayout android:layout_width="40dp"
android:layout_height="fill_parent"></LinearLayout>
</LinearLayout>

Categories

Resources