How Can I Do Text Box(left side) - android

Look the left side, how can I do it? It's only text; user can't click it because it's for info.

you need to set:
android:layout_alignParentLeft="true"
to what ever you want to align to the left
like i did in my example that looks a bit like yours, although i couldn't clearly understand what you wanted.
<?xml version="1.0" encoding="utf-8"?>
<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="apps.radwin.testprojectone.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Thats Only for text.(notClickable)"
android:textColor="#f00000"
android:layout_alignParentLeft="true"
android:id="#+id/textView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="-"
android:id="#+id/textView2"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="-"
android:id="#+id/textView3"
android:layout_below="#+id/textView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="-"
android:id="#+id/textView4"
android:layout_below="#+id/textView3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView5"
android:layout_below="#+id/textView2"
android:layout_centerHorizontal="true" />
</RelativeLayout>
the result of this would be an image like that:

You can create layout like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:text="That's pnly for text(not clickable)"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_marginLeft="10dp"
android:layout_width="10dp"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="Info"/>
<LinearLayout
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:text="Hello World"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

Related

android: position a textview below another textview

How to set texView2 below textView1?
I want to add second text view below first text view.
I tried this Layout Code below:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UserID"
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:text="User name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="16sp"
/>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:background="#FFFFFF"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Add Friend"
android:textColor="#0099CC" />
</LinearLayout>
any help would be appreciated...
thank you...
use Relative Layout rather than Linear layout Or Set Linear Layout Orientation Vertical.
Using Relative Layout your Code Should like:
<?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"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UserID"
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:text="User name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="16sp"
/>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:background="#FFFFFF"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Add Friend"
android:textColor="#0099CC" />
</RelativeLayout>
Or use LinearLayout Set Orientation To vertical if you want all Item Below one another than: your Code should be.
<?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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="8dp"
android:paddingBottom="8dp"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UserID"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="16sp"
/>
</LinearLayout>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:layout_below="#+id/linearLayout"
android:background="#FFFFFF"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Add Friend"
android:textColor="#0099CC" />
</RelativeLayout>
read this artical for linear layout and relative layout
LinearLayout
RelativeLayout
Just change the orientation of linearLayout to vertical and its go
<?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:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UserID"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="16sp"
/>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:background="#FFFFFF"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Add Friend"
android:textColor="#0099CC" />

Android Studio Element above another

I just started "programming" in Android Studio and i can't make 1 element above another one.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.example.krzysztofbzoma.minutnik.MainActivity">
<TextView
android:id="#+id/dwukropek"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textSize="50dp"
android:text=":" />
<TextView
android:id="#+id/minuta_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#id/minuta_2"
android:textSize="50dp"
android:text="0" />
<TextView
android:id="#+id/minuta_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#id/dwukropek"
android:textSize="50dp"
android:text="0" />
<TextView
android:id="#+id/sekunda_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#id/dwukropek"
android:textSize="50dp"
android:text="0" />
<TextView
android:id="#+id/sekunda_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textSize="50dp"
android:layout_toRightOf="#id/sekunda_1"
android:text="0" />
</RelativeLayout>
I need make 2 button above every "0". One under and one above it like on the picture. It need to have width same as this number and be aligned to it so it won't move if i rotate screen. I tried with another layouts but i don't understand difference between LinearLayouts and RelativeLayouts.
Picture example
check this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.krzysztofbzoma.minutnik.MainActivity">
<LinearLayout
android:id="#+id/LL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/minuta_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="50dp" />
<TextView
android:id="#+id/minuta_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="50dp" />
<TextView
android:id="#+id/dwukropek"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=":"
android:textSize="50dp" />
<TextView
android:id="#+id/sekunda_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="50dp" />
<TextView
android:id="#+id/sekunda_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textSize="50dp" />
</LinearLayout>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/LL"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="72dp"
android:layout_marginStart="72dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/LL"
android:layout_alignLeft="#+id/button2"
android:layout_alignStart="#+id/button2" />
</RelativeLayout>

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>

Why can't I use fill_parent on EditText's width in my XML file?

When I use fill_parent on the width of my EditText, the autofill of AndroidStudio shows it crossed out. If I still try using it it messes up the positioning of the EditText by throwing it out of the screen. I just want to have a simple text field and next to it an input text field which occupies the remaining of the screen.
Here is the code:
<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="com.kristmiha.registrationtest.MainActivity">
<TextView
android:id="#+id/headline1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="#string/hello"
android:textSize="32sp" />
<TextView
android:id="#+id/headline2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/headline1"
android:text="#string/register_here"
android:gravity="center"
android:textSize="24sp" />
<TextView
android:id="#+id/tvFirstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Name"
android:layout_below="#+id/headline2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp" />
<EditText
android:id="#+id/etFirstName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/tvFirstName"
android:layout_toRightOf="#+id/tvFirstName"
android:layout_toEndOf="#+id/tvFirstName" />
EDIT: Here is the position of the text field:
You should try this. With some modification you can achieve what you want.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/textView"
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="Medium Text"
android:id="#+id/textView2"
android:layout_below="#+id/textView"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/textView3"
android:layout_alignBottom="#+id/editText2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText2"
android:layout_below="#+id/textView2"
android:layout_toRightOf="#+id/textView3"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="#+id/textView4"
android:layout_alignBottom="#+id/editText3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText3"
android:layout_below="#+id/textView3"
android:layout_toRightOf="#+id/textView4"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
try this
<TextView
android:id="#+id/headline1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="Hellow world!!"
android:textSize="32sp" />
<TextView
android:id="#+id/headline2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#+id/headline1"
android:text="Register Here"
android:gravity="center"
android:textSize="24sp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/headline2"
android:layout_marginTop="20dp">
<TextView
android:id="#+id/tvFirstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Name"
/>
<EditText
android:id="#+id/etFirstName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
/>
</LinearLayout>
In relative layout
<TextView
android:id="#+id/tvFirstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Name"
android:layout_below="#+id/headline2"
android:layout_marginTop="20dp"
android:layout_alignBottom="#+id/etFirstName"
android:gravity="center"
/>
<EditText
android:id="#+id/etFirstName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
android:layout_below="#+id/headline2"
android:layout_toRightOf="#+id/tvFirstName"
android:layout_toEndOf="#+id/tvFirstName"
android:layout_marginTop="20dp"
/>
fill_parent value is deprecated use match_parent
Here you can see more and here more
Special value for the height or width requested by a View. FILL_PARENT
means that the view wants to be as big as its parent, minus the
parent's padding, if any. This value is deprecated starting in API
Level 8 and replaced by MATCH_PARENT.
For your problem : you should use this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="test.com.temp.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="label"
android:id="#+id/labelOne"
android:layout_alignBaseline="#+id/input"
/>
<EditText
android:id="#+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/labelOne"
android:layout_toEndOf="#+id/labelOne"
/>
</RelativeLayout>

How to place textview on the layout border in android?

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>

Categories

Resources