Not able to place my TextView right - android

Can anyone help me with placing my undertitle right under the title?
I'm relatively new to android programming and sorry for my bad english :D
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/listIcon"
android:padding="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/facebook"/>
<TextView
android:id="#+id/listText"
android:layout_gravity="center_vertical"
android:padding="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title" />
<TextView
android:id="#+id/listTextDescription"
android:layout_gravity="center_vertical"
android:padding="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Undertitle" />
</LinearLayout>

Try this, just change your layout from LinearLayout to RelativeLayout
<?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="horizontal" >
<ImageView
android:id="#+id/listIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="8dp"
android:src="#drawable/facebook" />
<TextView
android:id="#+id/listText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_toRightOf="#+id/listIcon"
android:padding="8dp"
android:text="Title" />
<TextView
android:id="#+id/listTextDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_toRightOf="#+id/listText"
android:padding="8dp"
android:text="Undertitle" />
</RelativeLayout>

Try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/listIcon"
android:padding="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/facebook"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<TextView
android:id="#+id/listText"
android:layout_gravity="center_vertical"
android:padding="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title" />
<TextView
android:id="#+id/listTextDescription"
android:layout_gravity="center_vertical"
android:padding="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Undertitle" />
</LinearLayout>
</LinearLayout>

Related

How do i make some TextView right next to the ImageView in xml

How can i create some TextView beside an ImageView in xml? I've tried my best, but still I can't make it.
Like this:
Display frame
I need 4 texts containing the title and description. The texts are intended to describe the image, any pointers or help would be appreciated
This is my xml code(end up getting a messy layout)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:background="#android:color/white"
android:padding="#dimen/activity_vertical_margin"
android:orientation="vertical"
android:layout_height="match_parent">
<ImageView
android:id="#+id/img_item_photo"
android:layout_width="150dp"
android:layout_height="200dp"
android:layout_marginEnd="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:src="#drawable/oneplus_7_pro_r1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/img_item_photo"
android:layout_toRightOf="#id/img_item_photo"
android:orientation="vertical" >
<TextView
android:id="#+id/tv_item_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="165dp"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:text="#string/Hape_name"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_item_Desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_margin" />
</LinearLayout>
</RelativeLayout>
Just remove android:layout_marginBottom="165dp" from your textview
Try this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:background="#android:color/white"
android:layout_height="match_parent">
<ImageView
android:id="#+id/img_item_photo"
android:layout_width="150dp"
android:layout_height="200dp"
android:src="#drawable/ic_search_black" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/img_item_photo"
android:layout_toRightOf="#id/img_item_photo"
android:orientation="vertical" >
<TextView
android:id="#+id/tv_item_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/load_available"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_item_Desc"
android:text="#string/load_available"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
Also, try with LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:background="#android:color/white"
android:orientation="horizontal"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/img_item_photo"
android:layout_width="150dp"
android:layout_height="200dp"
android:src="#drawable/ic_search_black" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/load_available"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/load_available"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_item_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/load_available"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_item_Desc"
android:text="#string/load_available"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
You can simply do this view using ConstraintLayout and it will look like below image and I posted the XML also use this:
Small Note: AndroidX is used here. If you are not familiar with androidX then, please take a small break to know about androidX and then try this.
if you are using support library (not androidX) then replace androidx.constraintlayout.widget.ConstraintLayout with android.support.constraint.ConstraintLayout in below code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="#tools:sample/avatars" />
<TextView
android:id="#+id/tv_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin_8dp"
android:text="textView 1"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
android:textColor="#color/black"
app:layout_constraintBottom_toTopOf="#id/tv_2"
app:layout_constraintStart_toEndOf="#id/imageView1"
app:layout_constraintTop_toTopOf="#id/imageView1" />
<TextView
android:id="#+id/tv_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin_8dp"
android:text="textView 2"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
android:textColor="#color/black"
app:layout_constraintBottom_toTopOf="#id/tv_3"
app:layout_constraintStart_toEndOf="#id/imageView1"
app:layout_constraintTop_toBottomOf="#id/tv_1" />
<TextView
android:id="#+id/tv_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin_8dp"
android:text="textView 3"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
android:textColor="#color/black"
app:layout_constraintBottom_toTopOf="#id/tv_4"
app:layout_constraintStart_toEndOf="#id/imageView1"
app:layout_constraintTop_toBottomOf="#id/tv_2" />
<TextView
android:id="#+id/tv_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/margin_8dp"
android:text="textView 4"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
android:textColor="#color/black"
app:layout_constraintBottom_toBottomOf="#id/imageView1"
app:layout_constraintStart_toEndOf="#id/imageView1"
app:layout_constraintTop_toBottomOf="#id/tv_3" />
</androidx.constraintlayout.widget.ConstraintLayout>
You can use layout weight for better result in every case,as shown below,...
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:TextViewandroid="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/icons"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_margin="#dimen/margin_10dp"
android:layout_weight="1"
android:background="#color/icons"
android:gravity="center">
<ImageView
android:id="#+id/img_item_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/background_img" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="#color/icons">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_5dp"
android:background="#drawable/style_curve_accent"
android:text="Title"
android:textSize="#dimen/margin_15sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_5dp"
android:background="#drawable/style_edittext"
android:text="Descripltion is Here. Descripltion is Here."
android:textSize="#dimen/margin_15sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_5dp"
android:layout_marginTop="#dimen/margin_5dp"
android:background="#drawable/style_curve_accent"
android:text="Title"
android:textSize="#dimen/margin_20dp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_5dp"
android:background="#drawable/style_edittext"
android:text="Descripltion is Here.Descripltion is Here."
android:textSize="#dimen/margin_15sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_5dp"
android:background="#drawable/style_curve_accent"
android:text="Title"
android:textSize="#dimen/margin_20dp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_5dp"
android:background="#drawable/style_edittext"
android:text="Descripltion is Here.Descripltion is Here."
android:textSize="#dimen/margin_15sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_5dp"
android:background="#drawable/style_curve_accent"
android:text="Title"
android:textSize="#dimen/margin_20dp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_5dp"
android:background="#drawable/style_edittext"
android:text="Description is here. Description is Here."
android:textSize="#dimen/margin_15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
Hope this it will help you!
Thanks!!
Though your code seems fine with minor improvements.
Here is some alternate code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#android:color/white"
android:padding="#dimen/activity_vertical_margin"
android:orientation="horizontal"
android:layout_height="match_parent">
<ImageView
android:padding="10dp"
android:layout_weight="1"
android:id="#+id/img_item_photo"
android:layout_width="0dp"
android:layout_height="200dp"
android:src="#drawable/side_nav_bar" />
<LinearLayout
android:padding="10dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/tv_item_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_item_Desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test 1"
/>
<TextView
android:id="#+id/tv_item_name1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test"
android:layout_marginTop="5dp"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_item_Desc2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test 2"
/>
</LinearLayout>
Here is solution,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/img_item_photo"
android:layout_width="150dp"
android:layout_height="200dp"
android:layout_marginEnd="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin" />
<LinearLayout
android:id="+#id/layout_field"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/tv_item_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:text="Hape_name"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_item_Desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_margin" />
</LinearLayout>
</LinearLayout>
Add more textView inside layout_field.

How to put the TextView at the Center?

The following is the code of main.xml, which i have used to create a row adapter for JSON
<?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:padding="4dp"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_weight="0.88"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="pumpName"
android:id="#+id/tvPump" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Time"
android:id="#+id/tvTime"
android:gravity="center_vertical" />
</LinearLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ivIcon"
android:src="#drawable/yes" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
The above code produces no error but the Time TextView does not come at the center.
I have tried android:gravity="center" but it did not work.
This is the image of my android studio
Relative Layout could come in handy here like so:
<?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:padding="4dp">
<TextView
android:id="#+id/tvPump"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="pumpName"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/tvTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="Time"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:layout_width="wrap_content"
android:id="#+id/ivIcon"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_height="wrap_content"
android:src="#drawable/yes" />
</RelativeLayout>

Android Layout for calendar control

I am looking to build a layout as above using linear/relative layouts with textbox.
Any help is appreciated.
Add background style to root layout for rounded corner and done
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#999999"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="#FFFFFF"
android:text="25"
android:padding="5dp"
android:textColor="#000000"
android:textSize="60sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Sept \n2016"
android:padding="5dp"
android:textSize="25sp" />
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#999999"
android:layout_margin="20dp"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:layout_width="5dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#999999"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="#FFFFFF"
android:padding="10dp"
android:text="25"
android:textColor="#000000"
android:textSize="60sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Sept \n2016"
android:textColor="#android:color/white"
android:padding="10dp"
android:textStyle="bold"
android:textSize="35sp" />
</LinearLayout>
</LinearLayout>

button not displaying right side of the layout in android

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>

Android layout help customizing according to image

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>

Categories

Resources