android中的图例和字段集

Dah*_*vos 7 android fieldset legend

我想知道在android中是否可以执行这样的表单:

在此输入图像描述

此刻,我做了一个形状来生成边框(我使用这个形状作为我的线性布局的背景,但我不知道如何处理文本).

提前致谢.

Ale*_*s G 24

我已经设法使用以下技术获得标题框架.

  1. 使用FrameLayout的整体布局.

  2. 在里面为你的主要内容添加另一个布局 - 这可以是任何东西.对于此布局的背景,使用自定义XML drawable stroke来绘制框架.确保在此布局中添加边距,尤其是marginTop因为您需要一些空间来显示框架的标题.还添加一些填充,使其看起来更好.

  3. 使用TextView不透明背景和一些填充作为标题.将marginLeft其设置为合理的值以从左侧偏移标题.

这是我的XML:

<?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="fill_parent"
    android:background="@android:color/white">

    <!--  This is the main content -->
    <RelativeLayout
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:layout_margin="15dp" android:background="@drawable/frame"
        android:orientation="vertical" android:padding="20dp">

        <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:text="Main Content" android:layout_centerInParent="true" />

    </RelativeLayout>

    <!--  This is the title label -->
    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:background="@android:color/white" android:padding="5dp"
        android:text="Testing"
        android:layout_marginLeft="30dp" android:textColor="@android:color/black" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

执行时,我在应用程序上得到这个:

在此输入图像描述

您可以随意调整边距/填充以按照您需要的方式对齐标题.

  • 对于像我这样的人,并没有意识到应该在drawable/frame中应该是什么,这里是我的框架:<shape xmlns:android ="http://schemas.android.com/apk/res/android"> <stroke android :width ="1px"android:color ="@ android:color/darker_gray"/> <padding android:left ="1dp"android:top ="1dp"android:right ="1dp"android:bottom ="1dp" /> </形状> (2认同)