這將是listview行。 橙色背景btn_default_small_selected:
android:background="@drawable/btn_default_small_selected"
這將是listview行。 橙色背景btn_default_small_selected:
android:background="@drawable/btn_default_small_selected"
像這樣的東西應該讓你接近。基本上,你會首先定義橙色框。您只需要一個用於橙色漸變的NinePatch即可設置爲TextView背景。給它一些邊距(使橘子遠離邊緣)和一些填充(使文本遠離橙色框的邊緣)。然後爲「Palace」添加TextView,並將其對齊到左邊,並將右邊緣設置爲「toLeftOf」第一個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>
編輯:
<?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>
NinePatch:
謝謝,@ kcoppock。如果我需要在左側添加ImageView,我應該在末尾加上'android:layout_toLeftOf =「@ id/nametext」'和'android:layout_alignParentLeft =「true」'? – 2011-05-21 16:17:28
關閉!但是你實際上想要在兩個TextView之間添加它,給它'alignParentLeft',而不是'toLeftOf'。然後給'nametext' TextView一個'toRightOf'屬性引用ImageView。 – kcoppock 2011-05-21 16:20:53
@ kcoppock,圖像應該在左邊:image,nametext,timetext。 – 2011-05-21 17:31:00
那麼,有什麼問題?你實際上不明白的是什麼? – Egor 2011-05-21 15:26:43
如何創建具有固定寬度的第二個TextView元素並位於右側,當第一個TextView應該位於左側並且應該佔據整個剩餘空間時。 – 2011-05-21 15:29:21
你有什麼問題? – jkhouw1 2011-05-21 15:32:16