简体   繁体   English

如何在图片上创建布局?

[英]How to create layout like on the picture?

在此处输入图片说明

That will be listview row. 那将是列表视图行。 Orange background is btn_default_small_selected: 橙色背景为btn_default_small_selected:

android:background="@drawable/btn_default_small_selected" 

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. 您只需要一个NinePatch即可将橙色渐变设置为TextView背景。 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. 然后为“ Palace”添加TextView,并将其向左对齐,并将第一个TextView的右边缘设置为“ toLeftOf”。

<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>

在此处输入图片说明

NinePatch: NinePatch: 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM