android - 如何在 Android 中创建带标题的边框?

标签 android titled-border

有人知道如何创建像 swing 中那样的带标题的边框布局吗? ?

关于 this我发现了一个在对象之间生成矩形的技巧。也许这可以帮助我创建这样一个带标题的边框?

问候

最佳答案

快速而肮脏:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" 
android:color="#000000">
<View
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/rectangle"
    android:layout_margin="20dp"
    />
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:background="#000000"
        android:layout_marginTop="10dp"
        android:text="TITLE!"
        android:textColor="#ffffff"/>
</RelativeLayout>

</FrameLayout>

@drawable/rectangle 在可绘制的 rectangle.xml 文件中,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle">
<solid android:color="@android:color/transparent"/>
<stroke  android:width="2dip" android:color="#ffffff"/>  
</shape>

关于android - 如何在 Android 中创建带标题的边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14636799/

相关文章:

Android Studio Windows : Debugger process finished with exit code -1073741515 (0xC0000135)

java - 如何以编程方式查找 Activity 的 list 选项?

java - jspinner 标题边框被切断

java - TitledBorder 标题更新/刷新延迟,为什么?

java - 双击 TitledBorder 即可编辑

android - dexguard 库无法加密类

android - 使用导航架构组件在 fragment 中显示备份/备份确认

android - 为什么在 "Google Play Games"中不显示 "Leaderboard"和 "Features"选项卡?

java - 使 TitledBorder 标题可编辑