0

我想创建一个如下图所示的视图。我的实现有一些线性布局。一个带有自定义可绘制对象的根以获取圆角边缘,然后其他用于两个文本视图和视图分隔线。有没有更快更简单的方法来做到这一点?

在此处输入图像描述

4

2 回答 2

1

您可以只使用 1 个 LinearLayout,即根之一。LinearLayout 仅用于订购其他视图。因此,您需要做的是使用垂直方向并添加两个文本视图。

在第一个上,您将背景颜色设置为浅灰色。并记住使用重力作为中心,这样您的文本将被放置在文本视图的中心。

于 2012-09-11T18:10:47.737 回答
0

我没有太多时间,只是想快速提供一个示例。这是我针对您的问题的代码:

your_main_layout.xml

<?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:background="@drawable/your_bg.xml">

    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="my text" />

     <View
        android:id="@+id/seperator
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/tv1" />

      <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="2nd text here"
        android:layout_below="@+id/seperator" />

</RelativeLayout>

your_bg.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <corners
        android:radius="5dp"
        />
    <solid android:color="#fff" />
    <stroke android:color="#000" />

</shape>
于 2014-07-23T09:09:06.847 回答