I am trying to use the design tab in Android Studio to design my XML for my homescreen, however when i try and drag a button it realigned everything on the layout, eg like in the image below:
I want to arrange it so the buttons are a uniform size and aligned in a 2x3 table like the following
a b
c d
e f
I would like the image to remain in the same place as it is currently, with the text underneath also not to move.
Current XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:src="#drawable/amityapplogo"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/welcomeadmin"
android:id="#+id/textView"
android:layout_gravity="center_horizontal"
android:layout_below="#+id/imageView"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/mydetails"
android:id="#+id/mydetailsbutton"
android:layout_gravity="center_horizontal"
android:clickable="false"
android:layout_toStartOf="#+id/myhealthbutton"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="42dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/policydetails"
android:id="#+id/policydetailsbutton"
android:layout_gravity="center_horizontal"
android:layout_alignTop="#+id/mydetailsbutton"
android:layout_toRightOf="#+id/findaproviderbutton"
android:layout_toEndOf="#+id/findaproviderbutton" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/myhealth"
android:id="#+id/myhealthbutton"
android:layout_gravity="center_horizontal"
android:layout_toStartOf="#+id/contactusbutton"
android:layout_centerVertical="true"
android:layout_alignLeft="#+id/textView"
android:layout_alignStart="#+id/textView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/findaprovider"
android:id="#+id/findaproviderbutton"
android:layout_gravity="center_horizontal"
android:layout_toStartOf="#+id/myhealthbutton"
android:layout_below="#+id/visitourwebsitebutton"
android:layout_alignLeft="#+id/imageView"
android:layout_alignStart="#+id/imageView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/contactus"
android:id="#+id/contactusbutton"
android:layout_gravity="center_horizontal"
android:layout_toEndOf="#+id/textView"
android:layout_below="#+id/visitourwebsitebutton"
android:layout_alignRight="#+id/imageView"
android:layout_alignEnd="#+id/imageView"
android:layout_marginTop="40dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/visitourwebsite"
android:id="#+id/visitourwebsitebutton"
android:layout_gravity="center_horizontal"
android:layout_toEndOf="#+id/myhealthbutton"
android:layout_alignBaseline="#+id/myhealthbutton"
android:layout_alignBottom="#+id/myhealthbutton"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Cheers in advance!
Added tablerows, now all is aligned to the left hand side:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="fill_horizontal"
android:id="#+id/">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:src="#drawable/amityapplogo" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/welcomeadmin"
android:id="#+id/textView"
android:layout_gravity="center_horizontal" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_column="1"
android:orientation="horizontal"
android:id="#+id/">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/mydetails"
android:id="#+id/mydetailsbutton"
android:layout_column="0" />
</TableRow>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/policydetails"
android:id="#+id/policydetailsbutton" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/myhealth"
android:id="#+id/myhealthbutton" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/findaprovider"
android:id="#+id/findaproviderbutton" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/visitourwebsite"
android:id="#+id/visitourwebsitebutton" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/contactus"
android:id="#+id/contactusbutton"
android:layout_gravity="center_vertical" />
</TableRow>
</TableLayout>
Try this and let me know
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:src="#drawable/amityapplogo"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/welcomeadmin"
android:id="#+id/textView"
android:layout_gravity="center_horizontal"
android:layout_below="#+id/imageView"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/mydetails"
android:id="#+id/mydetailsbutton"
android:clickable="false"
android:layout_marginTop="36dp"
android:layout_below="#+id/findaproviderbutton"
android:layout_alignRight="#+id/myhealthbutton"
android:layout_alignEnd="#+id/myhealthbutton" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/policydetails"
android:id="#+id/policydetailsbutton"
android:layout_toStartOf="#+id/mydetailsbutton"
android:layout_above="#+id/findaproviderbutton"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="36dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/myhealth"
android:id="#+id/myhealthbutton"
android:layout_toEndOf="#+id/imageView"
android:layout_below="#+id/policydetailsbutton"
android:layout_alignLeft="#+id/imageView"
android:layout_alignStart="#+id/imageView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/findaprovider"
android:id="#+id/findaproviderbutton"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/mydetailsbutton"
android:layout_toStartOf="#+id/mydetailsbutton" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/contactus"
android:id="#+id/contactusbutton"
android:layout_toEndOf="#+id/imageView"
android:layout_alignBottom="#+id/policydetailsbutton"
android:layout_alignLeft="#+id/myhealthbutton"
android:layout_alignStart="#+id/myhealthbutton" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/visitourwebsite"
android:id="#+id/visitourwebsitebutton"
android:layout_toEndOf="#+id/policydetailsbutton"
android:layout_alignBottom="#+id/mydetailsbutton"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/contactusbutton"
android:layout_toStartOf="#+id/contactusbutton" />
</RelativeLayout>
Here is what it look without assets
Comes to this(At Paul's , with assets):
This might work
<?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" >
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:text="ggggg"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/mydetailsbutton"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/textView"
android:layout_marginTop="42dp"
android:text="Details" />
<Button
android:id="#+id/policydetailsbutton"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/mydetailsbutton"
android:layout_alignTop="#id/mydetailsbutton"
android:layout_alignBottom="#id/mydetailsbutton"
android:text="eeeee" />
<Button
android:id="#+id/myhealthbutton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/mydetailsbutton"
android:layout_alignLeft="#id/mydetailsbutton"
android:layout_alignRight="#id/mydetailsbutton"
android:text="ddddd" />
<Button
android:id="#+id/findaproviderbutton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/mydetailsbutton"
android:layout_alignLeft="#id/policydetailsbutton"
android:layout_alignRight="#id/policydetailsbutton"
android:text="ccccc" />
<Button
android:id="#+id/contactusbutton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/myhealthbutton"
android:layout_alignLeft="#id/mydetailsbutton"
android:layout_alignRight="#id/mydetailsbutton"
android:text="bbbbb" />
<Button
android:id="#+id/visitourwebsitebutton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#id/myhealthbutton"
android:layout_alignLeft="#id/policydetailsbutton"
android:layout_alignRight="#id/policydetailsbutton"
android:text="aaaaa" />
</RelativeLayout>
You can use LinearLayouts inside another LinearLayout just like 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="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="Button1" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="Button2" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="Button3" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="Button4" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="Button5" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:text="Button6" />
</LinearLayout>
</LinearLayout>
You can add the ImageView and TextView before the first LinearLayout that keeps the first two Buttons.
Related
<?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:background="#00b9e8"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin" >
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:background="#ffffff" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Serch"
android:textColor="#000"
android:textSize="20sp" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView2"
android:layout_marginRight="32dp"
android:src="#drawable/backbutton" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#6AED83"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Footer"
android:textColor="#000000"
android:textSize="20sp" />
</RelativeLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="122dp"
android:text="Enter Mobile Number"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff"
android:textSize="20dp" />
<LinearLayout
android:id="#+id/layout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginLeft="14dp"
android:layout_marginTop="16dp"
android:background="#drawable/roundedlinearlayout3"
android:weightSum="4" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/user_s_icon" />
<EditText
android:id="#+id/editText1"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:hint="Enter Mobile Number"
android:textColorHint="#0060a4" >
</EditText>
</LinearLayout>
<Button
android:id="#+id/signin"
android:layout_width="244dip"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/layout1"
android:layout_below="#+id/layout1"
android:layout_marginTop="27dp"
android:background="#drawable/rounded"
android:text="Search"
android:textColor="#ffffff"
android:textSize="10pt" />
</RelativeLayout>
This is my Xml i am Unable to set Linear layout inside text view and image button Like desire image:
This is my desire screen : below is my current screen :
i am unable to set text-view and image view on top of Linear layout
Try this way,hope this will help you to solve your problem.
Instead of using RelativeLayout use LinearLayout which can be easily done your requirement.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00b9e8"
android:orientation="vertical">
<LinearLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:gravity="center"
android:background="#ffffff" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Serch"
android:textColor="#000"
android:textSize="20sp" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1"/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/backbutton" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter Mobile Number"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff"
android:textSize="20dp" />
<LinearLayout
android:id="#+id/layout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_marginTop="10dp"
android:background="#drawable/roundedlinearlayout3">
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Mobile Number"
android:textColorHint="#0060a4"
android:drawableLeft="#drawable/user_s_icon">
</EditText>
</LinearLayout>
<Button
android:id="#+id/signin"
android:layout_width="244dip"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/rounded"
android:text="Search"
android:textColor="#ffffff"
android:textSize="10pt" />
</LinearLayout>
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#6AED83"
android:gravity="center"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Footer"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
I have a listview with a custom adapter. I am trying to show subtext under an item. This is the xml I am using. The problem is that both TextView merge together. What can I do?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tijd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:paddingLeft="10dp" />
<TextView
android:id="#+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_below="#id/tijd"/>
<ImageView
android:id="#+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/tijd" />
</RelativeLayout>
You can try it like below,
<?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="wrap_content" >
<ImageView
android:id="#+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher" />
<TextView
android:id="#+id/tijd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:layout_toRightOf="#+id/type"
android:text="abcde" />
<TextView
android:id="#+id/sub"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tijd"
android:layout_toRightOf="#+id/type"
android:text="abcd" />
</RelativeLayout>
And your output will be as,
use layout below and centerhorizontal for sub
<TextView
android:id="#+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tijd"
android:centerHorizontal="true"
android:text="abcd" />
I think, you have to remove the centerInParent from the sub.
Try this
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="#+id/tijd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="title" />
<TextView
android:id="#+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="subtitle" />
</LinearLayout>
</LinearLayout>
Try this :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tijd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:text="Heading" />
<TextView
android:id="#+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/tijd"
android:layout_centerInParent="true"
android:text="Subheading" />
<ImageView
android:id="#+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#id/tijd"
android:background="#drawable/ic_launcher" />
Try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/type"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/tijd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="adad" />
<TextView
android:id="#+id/sub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="adad" />
</LinearLayout>
</LinearLayout>
Hope it will work.
I have made a simple application, with a background image, 4 image buttons and 4 text views in front of them.
I've read the google development documentation, but I still don't understand why in screens with a different size of 4,7" the app doesn't run normally. The textview is not in the right place. The image buttons are too small or too big in wrong places
I've created different images for differente resolutions (ldpi, mdpi, hdpi,xhdpi).
Here is the xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gameinterface"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".QuestionsActivity" >
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="95dp"
android:layout_marginRight="10dp"
android:layout_marginTop="137dp"
android:orientation="vertical" >
<TextView
android:id="#+id/tvQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:gravity="center_vertical|center_horizontal"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" >
<TextView
android:id="#+id/tvNumQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#B22222"
android:textSize="30sp" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/20"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#B22222"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout3"
android:layout_alignLeft="#+id/linearLayout4"
android:layout_marginBottom="114dp" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="#+id/btnR1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selector"
android:src="#drawable/answerbutton" />
<TextView
android:id="#+id/tvR1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#android:color/white"
android:textSize="10sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" >
<ImageButton
android:id="#+id/btnR3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selector"
android:src="#drawable/answerbutton" />
<TextView
android:id="#+id/tvR3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#android:color/white"
android:textSize="10sp" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="#+id/btnR2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selector"
android:src="#drawable/answerbutton" />
<TextView
android:id="#+id/tvR2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#android:color/white"
android:textSize="10sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" >
<ImageButton
android:id="#+id/btnR4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/selector"
android:src="#drawable/answerbutton" />
<TextView
android:id="#+id/tvR4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#android:color/white"
android:textSize="10sp" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
I have this xml layout, but the problem is that, in the scroll view, the height of it is spanning the whole screen and overlapping the bottom linear layout (drawing on top of it). Is there a way so that, I can get the scroll view height going only up to the linear layout on the bottom? I want the bottom 2 buttons to be aligned to the bottom of the screen.
Thanks
<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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".ActivityProfile" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
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:orientation="horizontal" >
<ImageView
android:id="#+id/picture_avatar"
android:layout_width="90dp"
android:layout_height="310dp"
android:background="#bdbdbd"
android:src="#drawable/no_avatar" />
<TextView
android:id="#+id/textview_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="" />
</LinearLayout>
<TextView
android:id="#+id/textview_fullname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="" />
<TextView
android:id="#+id/textview_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="email"
android:text="" />
<TextView
android:id="#+id/textview_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone"
android:text="" />
<TextView
android:id="#+id/textview_website"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:text="" />
<TextView
android:id="#+id/textview_bio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:layout_marginBottom="7dp"
android:text="" />
<TextView
android:id="#+id/textview_lastactive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/textview_datejoined"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/textview_dateleft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal" >
<Button
android:id="#+id/button_logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="CloseActivity"
android:text="#+string/back" />
<Button
android:id="#+id/button_exit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="GoToEditProfile"
android:text="#+string/edit" />
</LinearLayout>
</RelativeLayout>
Change it to LinearLayout and use layout_weight :
<?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">
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<LinearLayout
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:orientation="horizontal" >
<ImageView
android:id="#+id/picture_avatar"
android:layout_width="90dp"
android:layout_height="310dp"
android:background="#bdbdbd"
android:src="#drawable/no_avatar" />
<TextView
android:id="#+id/textview_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="" />
</LinearLayout>
<TextView
android:id="#+id/textview_fullname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="" />
<TextView
android:id="#+id/textview_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="email"
android:text="" />
<TextView
android:id="#+id/textview_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="phone"
android:text="" />
<TextView
android:id="#+id/textview_website"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:text="" />
<TextView
android:id="#+id/textview_bio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="7dp"
android:layout_marginBottom="7dp"
android:text="" />
<TextView
android:id="#+id/textview_lastactive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/textview_datejoined"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="#+id/textview_dateleft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal" >
<Button
android:id="#+id/button_logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="CloseActivity"
android:text="#+string/back" />
<Button
android:id="#+id/button_exit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="GoToEditProfile"
android:text="#+string/edit" />
</LinearLayout>
</LinearLayout>
hope help you.
in your linear layout (at the bottom) add it to be situated below the scrollview
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal"
android:layout_below=""#+id/scrollView1" <-- this code
>
and also change the main base layout to linearlayout so it wont overlap
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".ActivityProfile"
android:orientation='horizontal'
>
dont forget to change the tab at the very end
</LinearLayout>
I have an up with 3 buttons bat the bottom. When i test it on the emulator, the full screen appears. when i test it on my device, the buttons below does not show. it's like the resolution is incorrect. here is my xml 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:background="#raw/mexicanbg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/buttonbacksubreclist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:background="#drawable/back_button"
android:onClick="back" />
<TextView
android:id="#+id/textViewreclist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="45dp"
android:text="#string/reclist"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</LinearLayout>
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="382dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="362dp" >
<Button
android:id="#+id/buttonRecipes"
android:layout_width="108dp"
android:layout_height="wrap_content"
android:background="#drawable/menu_xrecipes"
android:onClick="recipe"
android:text="#string/rec" />
<Button
android:id="#+id/buttonGroList"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:background="#drawable/menu_xgrocery"
android:onClick="grocerylist"
android:text="#string/grolist" />
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/menu_xmore"
android:text="#string/more" />
</LinearLayout>
</LinearLayout>
EDIT:
New 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:background="#raw/mexicanbg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/buttonbacksubreclist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:background="#drawable/back_button"
android:onClick="back" />
<TextView
android:id="#+id/textViewreclist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="45dp"
android:text="#string/reclist"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</LinearLayout>
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="382dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="362dp" >
<Button
android:id="#+id/buttonRecipes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/menu_xrecipes"
android:onClick="recipe"
android:text="#string/rec" />
<Button
android:id="#+id/buttonGroList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/menu_xgrocery"
android:onClick="grocerylist"
android:text="#string/grolist" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/menu_xmore"
android:text="#string/more" />
</LinearLayout>
</LinearLayout>
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:background="#raw/mexicanbg"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/buttonbacksubreclist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:background="#drawable/back_button"
android:onClick="back" />
<TextView
android:id="#+id/textViewreclist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="45dp"
android:text="#string/reclist"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/real1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollX="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#+id/real1" >
<Button
android:id="#+id/buttonRecipes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/menu_xrecipes"
android:onClick="recipe"
android:text="#string/rec" />
<Button
android:id="#+id/buttonGroList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/menu_xgrocery"
android:onClick="grocerylist"
android:text="#string/grolist" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/menu_xmore"
android:text="#string/more" />
</RelativeLayout>
</RelativeLayout>
Replace last linear layout by relative layout and specify android:layout_alignParentBottom="true"
and also make RelativeLayout as your root Layout
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:background="#raw/mexicanbg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/buttonbacksubreclist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:background="#drawable/back_button"
android:onClick="back" />
<TextView
android:id="#+id/textViewreclist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="45dp"
android:text="#string/reclist"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp" >
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="200dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/buttonRecipes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/menu_xrecipes"
android:onClick="recipe"
android:text="#string/rec" />
<Button
android:id="#+id/buttonGroList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/menu_xgrocery"
android:onClick="grocerylist"
android:text="#string/grolist" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/menu_xmore"
android:text="#string/more" />
</LinearLayout>
</LinearLayout>
I found the answer ... The problem is not with t he buttons.. it is with my ListView. I did not put weight on my listview. Here is my final xml 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"
android:background="#raw/mexicanbg">
<LinearLayout
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:orientation="horizontal"
android:background="#drawable/xpage_label">
<TextView
android:id="#+id/textViewrecipe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:layout_marginBottom="10dp"
android:text="#string/rec"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
</LinearLayout>
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/menu_xrecipes"
android:onClick="recipe" />
<Button
android:id="#+id/buttonGroList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/menu_xgrocery"
android:onClick="grocerylist" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/menu_xmore" />
</LinearLayout>
</LinearLayout>