我们可以使用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>
但我需要一个像这样的图片标题的边框:
我该怎么做?
最佳答案
现在我找到了一个对我有帮助的好代码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/