android - Android 中带有标题的边框?

标签 android border shapes

我们可以使用shape来创建一个简单的边框,例如我看到这段代码here :

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <corners android:radius="5dip" />
            <solid android:color="@color/black" />
            <stroke android:width="2dip" android:color="@color/white" />
        </shape>
    </item>
</layer-list>

但我需要一个像这样的图片标题的边框:

enter image description here

我该怎么做?

最佳答案

现在我找到了一个对我有帮助的好代码here .我在这里添加代码:

<?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>

@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/15060425/

相关文章:

android - 是否可以制作一个应用程序(单击图标后)只需在浏览器中加载一个页面?

android - 将字符串数组传递给另一个 Activity

css - 在 <li> 下放置底部边框

ios - iphone怎么画椭圆和其他形状

java - 如何通过多态性消除这个特定的 SWITCH 语句

android - 带 Android Canvas 的圆角矩形

reporting-services - 在 SSRS 报表的 Tablix 中使用边框样式表达式

java - 是否可以更改 JTabbedPane 的布局?

缩放按钮的Android自定义形状

JavaFx 删除子节点会失去功能,但仍然存在