【问题标题】:legend and fieldset in androidandroid中的图例和字段集
【发布时间】:2012-08-22 17:31:48
【问题描述】:

我想知道在android中是否可以做这样的表格:

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

提前致谢。

【问题讨论】:

    标签: android legend fieldset


    【解决方案1】:

    我已经设法使用以下技术获得了一个带有标题的框架。

    1. 整体布局使用FrameLayout

    2. 在里面为你的主要内容添加另一个布局 - 这可以是任何东西。对于此布局的背景,使用带有stroke 的自定义 XML 可绘制对象来绘制框架。确保在此布局中添加边距,尤其是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>
    

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

    随意调整边距/内边距以按照您的需要对齐标题。

    【讨论】:

    • 我不认为它在不同的屏幕密度下会起作用。
    • @AdilMalik 只要你在任何地方都使用dp 单位,它就会。
    • 我刚试过你的代码。 ldpimdpi 设备略有不同。
    • 坦率地说,我认为没有人再关心 ldpi 了 :) 我已经在 mdpi、hdpi 和 xhdpi 中对其进行了测试 - 效果很好。
    • 对于像我这样的人,并没有意识到 drawable/frame 中应该包含什么,这是我的框架:schemas.android.com/apk/res/android"><strokeandroid:width="1px" android: color="@android:color/darker_gray" />跨度>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-15
    • 2012-09-13
    • 1970-01-01
    • 2018-02-24
    • 2016-05-05
    • 1970-01-01
    相关资源
    最近更新 更多