Android 如何创建具有圆角边和两个文本视图的自定义视图?
我想创建一个类似下图的视图。我的实现有一些线性布局。一个根具有自定义绘图功能,可获得圆角边,然后其他根用于两个文本视图和视图分隔符。有没有更快更简单的方法Android 如何创建具有圆角边和两个文本视图的自定义视图?,android,user-interface,layout,Android,User Interface,Layout,我想创建一个类似下图的视图。我的实现有一些线性布局。一个根具有自定义绘图功能,可获得圆角边,然后其他根用于两个文本视图和视图分隔符。有没有更快更简单的方法 只需1个线性布局(根布局)即可完成此操作。LinearLayout仅用于排序其他视图。因此,您需要做的是使用垂直方向并添加两个文本视图 在第一个选项中,将背景颜色设置为浅灰色。请记住使用重心作为中心,这样您的文本将被放置在文本视图的中心。我没有太多时间,只是尝试给出一个快速示例。以下是我回答您问题的代码: 您的_main_layout.xml
只需1个线性布局(根布局)即可完成此操作。LinearLayout仅用于排序其他视图。因此,您需要做的是使用垂直方向并添加两个文本视图
在第一个选项中,将背景颜色设置为浅灰色。请记住使用重心作为中心,这样您的文本将被放置在文本视图的中心。我没有太多时间,只是尝试给出一个快速示例。以下是我回答您问题的代码: 您的_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>
您可以通过自定义android:style/Theme.Dialog来实现这一点。您的意思是在LinearLayout上使用它吗?不,在活动清单上……要获得分隔符,您可以在它们之间使用框架布局,宽度为bakcground颜色黑色,高度为1dp
<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>