LA_
LA_

Reputation: 20429

How to create layout like on the picture?

enter image description here

That will be listview row. Orange background is btn_default_small_selected:

android:background="@drawable/btn_default_small_selected" 

Upvotes: 0

Views: 305

Answers (1)

Kevin Coppock
Kevin Coppock

Reputation: 134714

Something like this should get you close. Basically, you'll define the orange box first. You just need a NinePatch for the orange gradient to set as the TextView background. Give it some margins (to keep the orange away from the edges), and some padding (to keep the text away from the edge of the orange box). Then add the TextView for "Palace", and align it to the left, and set the right edge "toLeftOf" the first TextView.

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/gray_background_ninepatch"
    >
    <TextView
        android:id="@+id/timetext"
        android:layout_alignParentRight="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:padding="8dp"
        android:background="@drawable/orange_background_ninepatch"
        android:text="1:25 - 4:50"
        />
    <TextView
        android:id="@+id/nametext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/timetext"
        android:layout_alignParentLeft="true"
        android:text="Palace"
        />
</RelativeLayout>

EDIT:

<?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="50dp"
    android:gravity="center"
    android:background="@drawable/gray_background_ninepatch"
    >
    <TextView
        android:id="@+id/timetext"
        android:layout_alignParentRight="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:padding="8dp"
        android:background="@drawable/orange_background_ninepatch"
        android:text="1:25 - 4:50"
        android:textStyle="bold"
        android:textColor="@android:color/white"
        />
    <ImageView
        android:id="@+id/imageview"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_margin="5dp"
        android:alignParentLeft="true"
        android:src="@drawable/icon"
        android:scaleType="fitCenter"
        />
    <TextView
        android:id="@+id/nametext"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center_vertical"
        android:layout_toLeftOf="@id/timetext"
        android:layout_toRightOf="@id/imageview"
        android:text="Palace"
        android:textColor="@android:color/white"
        />
</RelativeLayout>

enter image description here

NinePatch: enter image description here

Upvotes: 1

Related Questions