2011-05-21 122 views
0

enter image description here如何在图片上创建布局?

这将是listview行。 橙色背景btn_default_small_selected:

android:background="@drawable/btn_default_small_selected" 
+0

那么,有什么问题?你实际上不明白的是什么? – Egor 2011-05-21 15:26:43

+0

如何创建具有固定宽度的第二个TextView元素并位于右侧,当第一个TextView应该位于左侧并且应该占据整个剩余空间时。 – 2011-05-21 15:29:21

+0

你有什么问题? – jkhouw1 2011-05-21 15:32:16

回答

1

像这样的东西应该让你接近。基本上,你会首先定义橙色框。您只需要一个用于橙色渐变的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> 

enter image description here

NinePatch: enter image description here

+0

谢谢,@ kcoppock。如果我需要在左侧添加ImageView,我应该在末尾加上'android:layout_toLeftOf =“@ id/nametext”'和'android:layout_alignParentLeft =“true”'? – 2011-05-21 16:17:28

+0

关闭!但是你实际上想要在两个TextView之间添加它,给它'alignParentLeft',而不是'toLeftOf'。然后给'nametext' TextView一个'toRightOf'属性引用ImageView。 – kcoppock 2011-05-21 16:20:53

+0

@ kcoppock,图像应该在左边:image,nametext,timetext。 – 2011-05-21 17:31:00