Hi in this Layout i have two button's named as back and home same names i mentioned as id's for both.Now left side i want to display back button and right side corner i want to display home.But home button not displaying at the right corner.Now if i mention margin left it's not showing properly.Can any one please help me
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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#FF0000"
android:orientation="horizontal">
<Button
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
/>
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textStyle="bold"
/>
<Button
android:id="#+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/home"
android:layout_marginLeft="60dp"
/>
</LinearLayout>
</LinearLayout>
Try this,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#FF0000"
android:orientation="horizontal"
android:weightSum="100" >
<Button
android:id="#+id/back"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="20"
android:background="#drawable/back" />
<TextView
android:id="#+id/tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="60"
android:gravity="center"
android:text="Hello"
android:textStyle="bold" />
<Button
android:id="#+id/home"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginLeft="60dp"
android:layout_weight="20"
android:background="#drawable/home" />
</LinearLayout>
</LinearLayout>
Try below code xml file:
<?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" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#FF0000"
android:orientation="horizontal">
<Button
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#drawable/back"
/>
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textStyle="bold"
/>
<Button
android:id="#+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/home"
android:layout_alignParentRight="true"
android:layout_marginLeft="60dp"
/>
</RelativeLayout>
</LinearLayout>
Try this way,hope this will help you to solve your problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#FF0000"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textStyle="bold"/>
</LinearLayout>
<Button
android:id="#+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/home"/>
</LinearLayout>
why don't you use relative layout for that, see that
<?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" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#FF0000"
android:orientation="horizontal" >
<Button
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/account_settings" />
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textStyle="bold" />
<Button
android:id="#+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/account_settings"
android:gravity="center_horizontal" />
</RelativeLayout>
</LinearLayout>
if you want to do this with linear layout use weight sum
<LinearLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#FF0000"
android:weightSum="3"
android:orientation="horizontal" >
<Button
android:id="#+id/back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/account_settings" />
<TextView
android:id="#+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:textStyle="bold" />
<Button
android:id="#+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:layout_weight="1"
android:background="#drawable/account_settings" />
</LinearLayout>
</LinearLayout>
Related
I'm beginner in android,and want to write xml file show two button center of screen horizontally,write this code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<TextView android:text="#+id/TextView01" android:id="#+id/TextView01"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<Button
android:id="#+id/allow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/TextView01"
android:text="Allow"/>
<Button
android:id="#+id/deny"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/allow"
android:layout_alignTop="#id/allow"
android:text="Deny"/>
</RelativeLayout>
that show me this:
but i want this:
Try this code. It will give desired 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">
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#+id/TextView01" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<Button
android:id="#+id/allow"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Allow" />
<Button
android:id="#+id/deny"
android:layout_width="wrap_content"
android:gravity="center"
android:layout_height="wrap_content"
android:text="Deny" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Try this:
<Button
android:id="#+id/allow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:text="Allow"/>
<Button
android:id="#+id/deny"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/allow"
android:layout_alignTop="#id/allow"
android:text="Deny"/>
First try changing your RelativeLayout height to android:layout_height="match_parent".
After that you could put both buttons in a LinearLayout like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerInParent="true">
<Button
android:id="#+id/allow"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Allow" />
<Button
android:id="#+id/deny"
android:layout_width="wrap_content"
android:gravity="center"
android:layout_height="wrap_content"
android:text="Deny" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="some text or #string reference from strings.xml" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
<Button
android:id="#+id/allow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Allow" />
<Button
android:id="#+id/deny"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Deny" />
</LinearLayout>
</RelativeLayout>
I just want to use multiple layout in a single xml file.I have attached my code below. In that there will be an absolute layout that should be under Horizontal scroll. As a beginner I don't know how to implement it
need your help friends..
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/aagr_background2"
android:orientation="vertical" >
<fragment
android:id="#+id/adview153613"
android:name="com.sentientit.theiWedplanner.Fragadmob"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<RelativeLayout
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#drawable/aanavigationbar" >
<Button
android:id="#+id/back"
android:layout_width="70dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="8dp"
android:layout_marginTop="3dp"
android:layout_x="8px"
android:layout_y="3px"
android:background="#drawable/custom_btn_breaker_bay"
android:text="Back"
android:textColor="#ffffff"
android:textSize="20sp" />
<Button
android:id="#+id/home"
android:layout_width="50px"
android:layout_height="30px"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/back"
android:layout_marginRight="46dp"
android:background="#drawable/home1"
android:paddingBottom="12px"
android:paddingTop="10px"
android:visibility="gone" />
</RelativeLayout>
<AbsoluteLayout
android:layout_width="fill_parent"
android:layout_height="61dp" >
<AbsoluteLayout
android:layout_width="fill_parent"
android:layout_height="61dp"
android:layout_x="120dp"
android:layout_y="35dp" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="38dp"
android:layout_y="30dp"
android:text="- Kid Seated"
android:textColor="#000000"
android:textSize="13dp"
android:typeface="serif" >
</TextView>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="6dp"
android:layout_y="28dp"
android:src="#drawable/kid" >
</ImageView>
</AbsoluteLayout>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="437dp"
android:layout_y="3dp"
android:src="#drawable/add11_table" />
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="48dp"
android:layout_y="4dp"
android:text="Line"
android:textSize="20sp" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="128dp"
android:layout_y="4dp"
android:text="circle"
android:textSize="20sp" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="212dp"
android:layout_y="6dp"
android:text="vshape"
android:textSize="20sp" />
</AbsoluteLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/table"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
</HorizontalScrollView>
</ScrollView>
Thank you in advance
Not sure whether your looking for this alignment but i just gave a shot..... whenever you wish to fix layout at the bottom of screen make sure you use weight property i.e if you want fix button at the bottom of screen then put android:layout_height = "0dp" and layout_weight="1" for other major layout in the xml and to button which has to be fixed at the bottom use android:layout_height="wrap_content" and layout_weight = "0" that's all is the trick (sorry if i have made it hard to understand... just simply saying play with weight and height property)
<?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:background="#fff"
android:orientation="vertical" >
<fragment
android:id="#+id/adview153613"
android:name="com.sentientit.theiWedplanner.Fragadmob"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<RelativeLayout
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:id="#+id/back"
android:layout_width="70dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="8dp"
android:layout_marginTop="3dp"
android:layout_x="8px"
android:layout_y="3px"
android:text="Back"
android:textColor="#ffffff"
android:textSize="20sp" />
<Button
android:id="#+id/home"
android:layout_width="50px"
android:layout_height="30px"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/back"
android:layout_marginRight="46dp"
android:paddingBottom="12px"
android:paddingTop="10px"
android:visibility="gone" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/table"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
</HorizontalScrollView>
</ScrollView>
<AbsoluteLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" >
<AbsoluteLayout
android:layout_width="fill_parent"
android:layout_height="61dp"
android:layout_x="120dp"
android:layout_y="35dp" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="38dp"
android:layout_y="30dp"
android:text="- Kid Seated"
android:textColor="#000000"
android:textSize="13dp"
android:typeface="serif" >
</TextView>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="6dp"
android:layout_y="28dp" >
</ImageView>
</AbsoluteLayout>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="437dp"
android:layout_y="3dp" />
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="48dp"
android:layout_y="4dp"
android:text="Line"
android:textSize="20sp" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="128dp"
android:layout_y="4dp"
android:text="circle"
android:textSize="20sp" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="212dp"
android:layout_y="6dp"
android:text="vshape"
android:textSize="20sp" />
</AbsoluteLayout>
</LinearLayout>
Yes, you can use use multiple layouts in single XML using the <include>.
Here is a example for that:
<?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="#color/app_background"
android:orientation="vertical" >
<include layout="#layout/actionbar_main" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<ImageView
android:id="#+id/img_rest_pic"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight=".35"
android:src="#drawable/upload_image" />
</LinearLayout>
</LinearLayout>
The actionbar_main.xml file is in different 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="?android:attr/actionBarSize"
android:background="#drawable/navbar_txt"
android:orientation="vertical" >
<ImageButton
android:id="#+id/ibtn_action_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:background="#null"
android:src="#drawable/navbar_back" />
<ImageButton
android:id="#+id/ibtn_action_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/ibtn_action_back"
android:layout_marginRight="5dp"
android:background="#null"
android:src="#drawable/nacbar_setting" />
<View
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignParentBottom="true"
android:background="#color/white" />
</RelativeLayout>
by setting four Buttons on a XML. I try this in the RelativeLayout, and for Galaxy Nexus 4 in the Graphicsl View it looks good, but when i change to another VIew like the Nexus 10 it looks horrible.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="com.example.b2.MainActivity"
tools:ignore="MergeRootFrame" >
<Button
android:id="#+id/button4"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:text="Button" />
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_above="#+id/button2"
android:layout_centerHorizontal="true"
android:text="Button" />
<Button
android:id="#+id/button3"
android:layout_width="180dp"
android:layout_height="80dp"
android:layout_above="#+id/button4"
android:layout_alignParentRight="true"
android:text="Button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_above="#+id/button4"
android:layout_alignParentLeft="true"
android:text="Button"
android:layout_toLeftOf="#+id/button3"
/>
</RelativeLayout>
<?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="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/white"
android:orientation="vertical"
android:gravity="center">
<Button
android:id="#+id/okbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="SET"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/white"
android:orientation="vertical"
android:gravity="center">
<Button
android:id="#+id/okbuttodn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="SET"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/white"
android:orientation="vertical"
android:gravity="center">
<Button
android:id="#+id/okbuttdtgyodn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="SET"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/white"
android:orientation="vertical"
android:gravity="center">
<Button
android:id="#+id/okbuttrtodn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="SET"
/>
</LinearLayout>
</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="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/white"
android:orientation="vertical"
android:gravity="center">
<Button
android:id="#+id/okbuttodn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="SET"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/white"
android:orientation="vertical"
android:gravity="center">
<Button
android:id="#+id/okbuttdtgyodn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="SET"
/>
</LinearLayout>
</LinearLayout>
use LinearLayout and android:layout_weight="size".
I am trying to make a layout in android according to the image however whatever i try is just wrong.
Here's my code below.
<?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="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:padding="8dp" >
<TextView
android:id="#+id/bottomright"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#E5E5E5"
android:layout_weight="1"
android:gravity="bottom|right"
android:textSize="15sp"
android:text="#string/bottomright" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:padding="8dp" >
<TextView
android:id="#+id/left"
android:layout_width="154dp"
android:layout_height="102dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:gravity="center|left"
android:layout_weight="1"
android:textSize="30sp"
android:adjustViewBounds="true"
android:maxLines="7"
android:text="" />
<TextView
android:id="#+id/topright"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="6dp"
android:gravity="top|right"
android:textSize="90sp"
android:text="topright" />
</LinearLayout>
</LinearLayout>
And here what i want to get. Maybe it is wrong to use LinearLayout? Better user Relative?
Can someone help me with this?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal"
android:weightSum="4" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="2" >
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top" />
</LinearLayout>
</LinearLayout>
Creating static xml layout's are very easy. I guess you haven't tried googling yourself.
anyways, with respect to the image, here is the code :-
<?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" >
<TextView
android:id="#+id/textView1"
android:layout_width="350dp"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="120dp"
android:layout_toRightOf="#+id/textView1"
android:text="TextView3" />
<TextView
android:id="#+id/textView3"
android:layout_width="fill_parent"
android:layout_height="120dp"
android:layout_toRightOf="#+id/textView1"
android:layout_below="#+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:text="TextView3" />
</RelativeLayout>
I want to have several layouts inside a layout so that I can better organize the UI. What I want is the layout to be horizontal. I need the layout to be split in half horizontally down the middle and the 4 buttons and text box to be on one side and copied on the other side as well so it can keep track of two totals. I only have one set of buttons right now because I cant get the layouts right.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="250.0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#id/button_add"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1.0"
android:text="+1" />
<Button
android:id="#id/button_add_5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1.0"
android:text="+5" />
</LinearLayout>
<EditText
android:id="#id/currentlife"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:inputType="number"
android:minWidth="120.0dip"
android:text="20"
android:textSize="40.0dip" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#id/button_minus"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1.0"
android:text="-1" />
<Button
android:id="#id/button_minus_5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1.0"
android:text="-5" />
</LinearLayout>
</LinearLayout>
How about this (fix id's so they aren't duplicate):
<?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="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1.0"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center"
>
<EditText
android:id="#+id/currentlife"
android:layout_width="wrap_content"
android:gravity="center"
android:minWidth="120dp"
android:layout_height="wrap_content"
android:inputType="number"
android:text="20"
android:textSize="40dp" />
</LinearLayout>
<LinearLayout
android:layout_height="0dp"
android:layout_width="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:gravity="center"
>
<Button
android:id="#+id/button_add"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="+1" />
<Button
android:id="#+id/button_add_5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="+5" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:orientation="horizontal"
android:gravity="center"
>
<Button
android:id="#+id/button_minus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-1" />
<Button
android:id="+#id/button_minus_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-5" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#android:color/black"/>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1.0"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center"
>
<EditText
android:id="#+id/currentlife"
android:layout_width="wrap_content"
android:gravity="center"
android:layout_height="wrap_content"
android:inputType="number"
android:minWidth="120dp"
android:text="20"
android:textSize="40dp" />
</LinearLayout>
<LinearLayout
android:layout_height="0dp"
android:layout_width="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:layout_gravity="right"
>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:gravity="center"
>
<Button
android:id="#+id/button_add"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="+1" />
<Button
android:id="#+id/button_add_5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="+5" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:orientation="horizontal"
android:gravity="center"
>
<Button
android:id="#+id/button_minus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-1" />
<Button
android:id="+#id/button_minus_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-5" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Give weight for two horizontal layouts.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1.0">
// try this and let me know is it ok for ur requirement ?
<?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="wrap_content"
android:padding="5dp"
android:gravity="center" >
<Button
android:id="#+id/button_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+1" />
<Button
android:id="#+id/button_add_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+5" />
<EditText
android:id="#+id/currentlife"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:inputType="number"
android:gravity="center"
android:text="20"
android:textSize="40dp" />
<Button
android:id="#+id/button_minus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-1" />
<Button
android:id="#+id/button_minus_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-5" />
</LinearLayout>
You can create left and right layouts as separate layouts and inflate it in the main layout. This will simplify the layout design.
And try to start the design with android:layout_width="fill_parent" instead of android:layout_width="250.0dip"
Once you get the layout you want, then try to adjust the width as you need.