I have the following layout
<?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" >
<ImageView
android:id="#+id/imageView1"
android:layout_gravity="center"
android:layout_width="200dip"
android:layout_height="200dip"
/>
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginLeft="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/tview_total"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Total Files Processed:" />
<TextView
android:id="#+id/tview_success"
android:layout_width="match_parent"
android:gravity="right"
android:layout_height="wrap_content"
android:text="Successfully Processed:" />
<TextView
android:id="#+id/tview_error"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Error Processing:" />
</LinearLayout>
<LinearLayout
android:id="#+id/llBottomContainer2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom"
android:gravity="bottom"
android:padding="5dp" >
<Button
android:id="#+id/proceed2"
style="#style/btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#drawable/btn_sel"
android:text="Proceed" />
</LinearLayout>
</LinearLayout>
I want to align the Button on the bottom of the screen.I tried setting
android:layout_gravity="bottom"
android:gravity="bottom"
Does not work.What i'm i doing wrong?
try this :
<LinearLayout
android:id="#+id/llBottomContainer2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_gravity="bottom"
android:gravity="bottom"
android:padding="5dp" >
try this layout :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="200dip"
android:layout_height="200dip"
android:layout_gravity="center" />
<ProgressBar
android:id="#+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:orientation="vertical" >
<TextView
android:id="#+id/tview_total"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Total Files Processed:" />
<TextView
android:id="#+id/tview_success"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Successfully Processed:" />
<TextView
android:id="#+id/tview_error"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="Error Processing:" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/llBottomContainer2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:orientation="vertical"
android:padding="5dp" >
<Button
android:id="#+id/proceed2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Proceed" />
</LinearLayout>
</RelativeLayout>
where android:layout_alignParentBottom="true" is key parameter.
Happy coding..
android:gravity="bottom"
Then make the gravity of layout or your button to the bottom
Related
I' am trying to achieve sth like this:
But the ListView is overlaps my bottom bar. What is the best way to prevent such a behaviour? As you can see in the picture there is a map under bottom bar. This bottom bar is like target/destination window in Google Maps app.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<com.google.android.gms.maps.MapView
android:id="#+id/map"
tools:layout="#layout/fragmentMap"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginTop="2dp"
android:orientation="vertical">
<EditText
android:id="#+id/mapEditT"
android:layout_width="fill_parent"
android:layout_height="53dp"
android:layout_alignParentTop="true"
android:gravity="center|left"
android:paddingLeft="2dp"
android:paddingRight="0dp"/>
<ListView
android:id="#+id/listVi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical">
<ImageButton
android:id="#+id/draweR"
android:layout_width="wrap_content"
android:src="#drawable/draweR"/>
<LinearLayout
android:id="#+id/infoBox"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="40dp"
android:alpha="0.1"
android:background="#android:color/black"
android:orientation="horizontal">
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:text="Info"
/>
<TextView
android:id="#+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_toRightOf="#id/text2"
android:text="Info/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
Use LinearLayout or RelativeLayout as top most parent instead of FrameLayout.
Here is the code snippet using LinearLayout.
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</ListView>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="#+id/draweR"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="left|center_vertical"
android:src="#drawable/draweR"/>
<com.google.android.gms.maps.MapView
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="#layout/fragmentMap" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100" >
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_weight="75" />
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="TextView"
android:layout_weight="25" />
</LinearLayout>
</LinearLayout>
You can mess around with the margins. I got it to look like the image you wanted.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.android.gms.maps.MapView
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="#layout/fragmentMap" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="2dp"
android:layout_marginRight="2dp"
android:layout_marginTop="2dp"
android:orientation="vertical"
android:paddingBottom="160dp" >
<EditText
android:id="#+id/mapEditT"
android:layout_width="fill_parent"
android:layout_height="53dp"
android:layout_alignParentTop="true"
android:gravity="center|left"
android:paddingLeft="2dp"
android:paddingRight="0dp" />
<ListView
android:id="#+id/listVi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="vertical" >
<ImageButton
android:id="#+id/draweR"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/draweR" />
<LinearLayout
android:id="#+id/infoBox"
android:layout_width="match_parent"
android:layout_height="100dp"
android:alpha="0.1"
android:background="#android:color/black"
android:orientation="horizontal" >
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:text="Info" />
<TextView
android:id="#+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_toRightOf="#id/text2"
android:text="Info" />
</LinearLayout>
</LinearLayout>
My images. such as
when i write something then show image like
But i want write something and show that also.
My Codes :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:background="#ffffff" >
<!-- Header aligned to top -->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<include
android:id="#+id/header"
layout="#layout/header" >
</include>
<!-- Footer aligned to bottom -->
<!-- Content below header and above footer -->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/locationLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UbicaciĆ³n"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/locationSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/deprtmentLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/locationLayout"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Departamento"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/departmentSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/folderpathLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/deprtmentLayout"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Carpeta"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/folderSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="#+id/locatioRnLayoutT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/folderpathLayout"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:gravity="center|end"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:text="comentario"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/etComments"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top|left"
android:hint="escribir comentario aquĆ"
android:inputType="textMultiLine"
android:lines="8"
android:maxLines="10"
android:minLines="4"
android:scrollbars="vertical" >
<requestFocus />
</EditText>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#0c95d4" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center" >
<ImageView
android:id="#+id/backImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#drawable/img_selector"
android:clickable="true"
android:onClick="doActions"
android:src="#drawable/back_black" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1" />
<ImageView
android:id="#+id/reportOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#drawable/img_selector"
android:clickable="true"
android:onClick="doActions"
android:src="#drawable/right_button_white" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#drawable/img_selector"
android:clickable="true"
android:onClick="doActions" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
And header.xml
<?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="50dp"
android:layout_alignParentTop="true"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="5" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<TextView
android:id="#+id/tvHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/layout"
android:layout_weight="4"
android:paddingLeft="8dp"
android:text="Fixed Header"
android:textColor="#33b5e5"
android:textSize="12sp" />
<RelativeLayout
android:id="#+id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" >
<ImageView
android:id="#+id/iHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="#drawable/img_selector"
android:clickable="true"
android:onClick="goToHome"
android:src="#drawable/home_black" />
<ImageView
android:id="#+id/ilogout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/iHome"
android:background="#drawable/img_selector"
android:clickable="true"
android:onClick="logoutAction"
android:paddingRight="8dp"
android:src="#drawable/logout_black" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<View
android:layout_width="match_parent"
android:layout_height="3dip"
android:background="#33b5e5" />
</LinearLayout>
</RelativeLayout>
when i write something on comment field then show pop-up windows for writing input then i don't show any text what i do write on EditText. How to show input field when i write some thing. please help me.
Set appropriate windowSoftInputMode for your activity in the manifest. adjustPan is probably what you're looking for there.
I'm trying to implement a relative layout, similar to below picture.
But when trying to bottom align the bottom-right text view, it goes out of the screen.
What is the best/minimal way to design below layout?
Code, currently I'm trying:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/dash1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top" >
<RelativeLayout
android:id="#+id/view_subdash_top_right"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/tv_name" >
<TextView
android:id="#+id/tv_instrument_change"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tv_text2"
android:gravity="right"
android:text="text1" />
<TextView
android:id="#+id/tv_text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="right"
android:text="text2" />
</RelativeLayout>
<TextView
android:id="#+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignBottom="#id/view_subdash_top_right"
android:gravity="bottom|center"
android:text="name" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/dash1"
android:gravity="top" >
<!-- Here to enter bottom left -->
<TextView
android:id="#+id/tv_bottom_right"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:gravity="right|bottom"
android:text="bottom right" />
</RelativeLayout>
</RelativeLayout>
// try 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"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/rel_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tv_top_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/rel_top_right"
android:text="Top Left Text" />
<RelativeLayout
android:id="#+id/rel_top_right"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="right"
android:layout_toRightOf="#id/tv_top_left" >
<TextView
android:id="#+id/tv_top_text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Top Text1" />
<TextView
android:id="#+id/tv_top_text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tv_top_text1"
android:text="Top Text2" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/rel_top"
android:gravity="top" >
<TextView
android:id="#+id/tv_bottom_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignBottom="#id/rel_bottom_left"
android:text="Bottom Right Text" />
<RelativeLayout
android:id="#+id/rel_bottom_left"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/tv_bottom_right" >
<TextView
android:id="#+id/tv_bottom_text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bottom Text1" />
<TextView
android:id="#+id/tv_bottom_text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tv_bottom_text1"
android:text="Bottom Text2" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
If you want to fill up the whole screen with those views, I'd use weighted LinearLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="4"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="4"/>
</LinearLayout>
</LinearLayout>
I'm Trying to get the buttons to go under the white box. In the java file I am adding a special view to the id:ViewLayout. I have tried putting the buttons after the Framelayout, but they dont appear on screen....
<TextView
android:id="#+id/tvClock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="12:00"
android:textColor="#android:color/white"
android:textSize="100dp" />
<FrameLayout
android:id="#+id/Container"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/ViewLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</RelativeLayout>
<Button
android:id="#+id/bUnlock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unlock" />
<Button
android:id="#+id/bPin"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PIN" />
</FrameLayout>
Thanks!
Try this one.
<?xml version="1.0" encoding="utf-8"?>
<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="fill_parent"
android:background="#android:color/black"
android:orientation="vertical" >
<TextView
android:id="#+id/tvClock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="12:00"
android:textColor="#android:color/white"
android:textSize="100dp" />
<LinearLayout
android:id="#+id/Container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.58" >
<LinearLayout
android:id="#+id/ViewLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/tvClock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="12:00"
android:textColor="#android:color/white"
android:textSize="100dp" />
<RelativeLayout
android:id="#+id/Container"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/ViewLayout"
android:layout_width="match_parent"
android:layout_height="100dp" >
</RelativeLayout>
<Button
android:id="#+id/bUnlock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unlock"
android:layout_below="#id/ViewLayout"
/>
<Button
android:id="#+id/bPin"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PIN"
android:layout_below="#id/bUnlock"/>
</RelativeLayout>
Try RelativeLayout instead of framelayout.
This may help you:
<TextView
android:id="#+id/tvClock"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:gravity="center"
android:text="12:00"
android:textColor="#android:color/white"
android:textSize="100dp"
android:layout_weight="2" />
<LinearLayout
android:id="#+id/Container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1">
<RelativeLayout
android:id="#+id/ViewLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<Button
android:id="#+id/bUnlock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Unlock" />
<Button
android:id="#+id/bPin"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PIN" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I want to place Image in the center and text just below it in a button, I tried to set android:gravity but could not set it properly,here is the image attached:
below is my xml:
<?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"
android:paddingLeft="10.0dip"
android:paddingTop="10.0dip"
android:paddingRight="10.0dip"
android:paddingBottom="10.0dip"
android:background="#drawable/background_img"
>
<LinearLayout
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingLeft="10.0dip"
android:paddingTop="10.0dip"
android:paddingRight="10.0dip"
android:paddingBottom="10.0dip"
>
<Button
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:id="#+id/button_listen"
android:text="#string/listen"
android:drawableTop="#drawable/listen_btn"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_gravity="center"
/>
<Button
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:id="#+id/button_gallery"
android:text="#string/gallery"
android:drawableTop="#drawable/gallery_btn"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_gravity="center"
/>
</LinearLayout>
<LinearLayout
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingLeft="10.0dip"
android:paddingTop="10.0dip"
android:paddingRight="10.0dip"
android:paddingBottom="10.0dip"
>
<Button
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:id="#+id/button_play"
android:text="#string/play"
android:drawableTop="#drawable/play_btn"
android:layout_marginLeft="10dp"
android:layout_gravity="center"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
<Button
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:id="#+id/button_find"
android:text="#string/find"
android:drawableTop="#drawable/test_btn"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_gravity="center"
/>
</LinearLayout>
</LinearLayout>
What is the proper way to center the image and text below it?
Many thanks in advance.
Try this its work for me
<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" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="151dp"
android:onClick="onClick"
android:drawableTop="#drawable/ic_launcher"
android:text="Button" />
</RelativeLayout>
Try change the button to LinearLayout and use same onclicklistener on fakebutton
<LinearLayout
android:id="#+id/fakeButton"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon_big_evento" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/menu_about" />
</LinearLayout>
I followed DjHacktorReborn comments and made the layout, here is the freezed one
<?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:background="#drawable/background_img"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="10" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="4.1"
android:orientation="vertical" >
</LinearLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="horizontal"
android:stretchColumns="*" >
<TableRow android:layout_weight="1" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/button_listen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="#drawable/main_list"
android:paddingTop="90dp"
android:text="#string/listen"
android:textStyle="bold"
android:textColor="#FFFFFF" />
<ImageView
android:id="#+id/main_icon_content_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/listen_btn" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/button_gallery"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/main_list"
android:paddingTop="90dp"
android:text="#string/gallery"
android:textStyle="bold"
android:textColor="#FFFFFF" />
<ImageView
android:id="#+id/main_icon_schedule_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/gallery_btn" />
</RelativeLayout>
</TableRow>
<TableRow android:layout_weight="1" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/button_play"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/main_list"
android:ellipsize="marquee"
android:paddingTop="90dp"
android:text="#string/play"
android:textStyle="bold"
android:textColor="#FFFFFF"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/play_btn" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/button_find"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/main_list"
android:paddingTop="90dp"
android:text="#string/find"
android:textStyle="bold"
android:textColor="#FFFFFF" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/test_btn" />
</RelativeLayout>
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="4.1"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</LinearLayout>
Here is the updated result
Thanks for the suggestions