I want to set list view between two hardcoded items. I can't leave the height value blank in listView, cause it's disappear. I try with wrap/fill.. but all this things making my listView fill whole layout. Here is my 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="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="#+id/choose_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/relativeLayout1" >
</ListView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:background="#drawable/buton_style" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="90dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/addToBasketName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Produkty:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/choose_produkty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do zapłaty:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/choose_do_zaplaty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/addToBasket"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Do kasy" />
</RelativeLayout>
How would you solve this problem?
By default , all your Views will be placed at the top left corner in your RelativeLayout. So you will usually want to add layout_below or layout_top to your component.
For a more detail description for RelativeLayout, see this
Try this one
<ListView
android:id="#+id/choose_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/relativeLayout1"
android:layout_below="#+id/textView1" >
Use a LinearLayout as the outmost container, and setthis to the ListView:
layout_height="0px
layout_weight="1"
// try this way
<?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:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="#+id/choose_list_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="5dp"
android:layout_weight="1">
</ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_weight="1">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/addToBasketName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Produkty:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/choose_produkty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do zapłaty:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/choose_do_zaplaty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/addToBasket"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do kasy" />
</LinearLayout>
</LinearLayout>
Related
I want to achieve this result:
Inside the middle layout I want place 2 textview.
I guess that I must to use a FrameLayout or a RelativeLayout to place the middle view in that position.
Another problem is I need that the text at the left of the middle layout(TEXT 1 and 2), doesn't go underneath it.
Thanks
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:background="#aa0000"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView121"
android:layout_weight="1" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView12"
android:layout_weight="1" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="54dp"
android:layout_weight="1"
android:background="#00aa00"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="New Text"
android:id="#+id/textView"
android:layout_weight="1" />
</RelativeLayout>
</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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight="0.3"
android:background="#FFFF0000"
android:orientation="horizontal" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight="0.7"
android:background="#FF0000FF"
android:orientation="horizontal"
android:weightSum="3">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFFF00FF"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFFFF" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FF00FFFF"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFFFF" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="153dp"
android:gravity="right"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFF0F0FF"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFFFF" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF0FFF0F"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFFFF" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
I am trying to create a Row layout to use in my ListView,
but when the text is too long, it pushes the right hand side ImageButton off the screen.
I want the text to just continue on the next line without interfering with the ImageButton-
This is the layout I have so far, I tried adding weight properties to set how much space could be use but I couldn't get it to work.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="#+id/ImageView"
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:orientation="vertical" >
<TextView
android:id="#+id/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/Text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/Text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/Text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/ImageButton"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:drawableTop="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Thank You.
No matter what lenght if text, first and last image will be of width 50dp occupied, rest space for text.
<LinearLayout
android:layout_width="50dp"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="#+id/ImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/Text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/Text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/Text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
android:layout_width="50dp"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/ImageButton"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:drawableTop="#drawable/ic_launcher" />
</LinearLayout>
You're using too many LinearLayouts, and also you're not defining any constrain for your views space.
Try this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/ImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:src="#drawable/ic_launcher" />
<ImageButton
android:id="#+id/ImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:drawableTop="#drawable/ic_launcher" />
<LinearLayout
android:id="#+id/LinearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/ImageButton"
android:layout_toRightOf="#id/ImageView"
android:orientation="vertical" >
<TextView
android:id="#+id/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/Text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/Text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/Text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</RelativeLayout>
I'm having trouble getting a layout looking like this:
Is it possible to do something like this:
<RelativeLayout>
<TextView
android:id="#+id/text1"
android:layout_alignParentLeft="true"/>
<TextView
android:layout_below="#id/text1/>
<LinearLayout
android:orientation="vertical"
android:layout_alignRightOf="#id/text1">
<ImageButton/>
<ImageButton/>
<ImageButton/>
</LinearLayout>
</RelativeLayout>
Or more specifically, is it possible to set an layout_align on , like this: android:layout_alignRightOf="#id/text1"
If not, how do I get this layout?
I don't know how (if possible) to do it with RelativeLayout, but with some LinearLayout should be quite easy, here a sample:
<?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_height="match_parent"
android:layout_weight="1"
android:background="#ff0000"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#aa0000ff"
android:layout_weight="1" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#aaff0000"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="#00ff00"
android:orientation="vertical" >
<ImageButton
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<ImageButton
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<ImageButton
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
In my opinion this is the perfect example for a LinearLayout. Take a look at the Linearlayouts weight property.
<?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="wrap_content"
android:layout_height="match_parent"
android:layout_weight="3"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:layout_width="80dp"
android:layout_height="240dp"
android:orientation="vertical" >
<ImageButton
android:id="#+id/ImageButton02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/icon_plus" />
<ImageButton
android:id="#+id/ImageButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/icon_plus" />
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/icon_plus" />
</LinearLayout>
</LinearLayout>
Create one parent relative layout which will have two child relative layouts
1. first child relative layout which will have left two textviews
2. Second child relative layout will have right side imageviews
Try like this
<RelativeLayout
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="0.5"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="0.5"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="wrap_content"
android:background="#ff4500"
android:orientation="vertical" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="#+id/textView1"
android:layout_width="212dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="0.33"
android:text="Large Text" />
<Button
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="0.33"
android:text="Large Text" />
<Button
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_weight="0.33"
android:text="Large Text" />
</LinearLayout>
</LinearLayout>
I need design this layout.
How do I keep two textview in horizontal on right of image view?
I am able to get 1 textview on the right of imageview but not both.
This is how i had tried.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/logo" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
What about 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" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/downvote" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
</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="match_parent"
android:orientation="vertical"
android:padding="5dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="3dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="textview1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="left|top"
android:lines="2"
android:text="textview2" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="left|top"
android:lines="2"
android:text="textview3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="left|top"
android:lines="4"
android:text="textview4" />
</LinearLayout>
</LinearLayout>
Use a relative layout instead. Set the ImageView to be android:layout_alignParentLeft="true" then set you TextViews to be android:layout_toRightOf on the ImageView.
you can use this code: with relative lay out this is easily done.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/imageView1" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textView1"
android:layout_gravity="right"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/imageView1"
android:layout_centerHorizontal="true" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/textView3"
android:layout_gravity="right"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
I am trying to create an layout as shown in the figure.
In that image shipped to is attached to the border of the layout. how to overlap like that.
Here is the XML I am using to create that
<RelativeLayout
android:id="#+id/shipped_to_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#drawable/address_blue_border" >
<TextView
android:id="#+id/tv_shipped_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/homebackground"
android:text="Shipped To"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/tv_door_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_shipped_to"
android:text="22"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/tv_address_line1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_door_no"
android:text="Delhi, India"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/tv_address_line2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_address_line1"
android:text="Swindon Senegal BS32 8FE"
android:textColor="#android:color/black" />
</RelativeLayout>
Try this
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="8dp"
android:background="#android:color/holo_blue_bright"
android:orientation="vertical"
android:padding="10dp" >
<TextView
android:id="#+id/tv_door_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="22" />
<TextView
android:id="#+id/tv_address_line1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delhi" />
<TextView
android:id="#+id/tv_address_line2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some more dara" />
</LinearLayout>
<TextView
android:id="#+id/tv_shipped_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Ship To"
android:background="#android:color/holo_blue_dark"
android:layout_marginLeft="15dp"
/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#android:color/white">
<!-- This is the main content -->
<RelativeLayout
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_margin="15dp" android:background="#drawable/frame"
android:orientation="vertical" android:padding="20dp">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Main Content" android:layout_centerInParent="true" />
</RelativeLayout>
<!-- This is the title label -->
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#android:color/white" android:padding="5dp"
android:text="Testing"
android:layout_marginLeft="30dp" android:textColor="#android:color/black" />
</RelativeLayout>
You can have your answer at here and here
To obtain a layout similar to the one it's in the image you have to use command android:layout_margin with negative values.
Here is an example:
<?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" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="TextView" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="TextView" />
</RelativeLayout>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/relativeLayout1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="-10dp"
android:text="TextView" />
</RelativeLayout>
Your image is a bit toooo small. Anyway, for that, use 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:padding="0dp" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="20dp"
android:background="#ccff00"
android:orientation="vertical" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<!-- Your other TextViews -->
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout1"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="#ccffff"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>