gpt4 book ai didi

安卓 : Border only on corners

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:15:12 27 4
gpt4 key购买 nike

在我的 android 应用程序中,我只需要在四个角上添加边框,如图(白色)所示。

enter image description here

    <RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="6">
<VideoView
android:id="@+id/video1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" />
<View
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerInParent="true"
android:background="@drawable/cornerbg" />
</RelativeLayout>

cornerbg.xml

        <?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item>
<shape android:shape="rectangle" >
<solid android:color="@color/transparent" />
<stroke
android:width="1dp"
android:color="@color/btn_border"
android:dashWidth="50dp" // I tried this but not getting expected
android:dashGap="60dp"/>

</shape>
</item>
</layer-list>

我如何为此编写 xml?

请帮忙,谢谢

最佳答案

下面是不依赖于矩形宽度和高度的可绘制对象,您可以将此可绘制对象用于纵向和横向。请调整边框的宽度和高度:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="8dp"
android:height="48dp"
android:gravity="top|left">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
<item
android:width="48dp"
android:height="8dp"
android:gravity="top|left">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
<item
android:width="8dp"
android:height="48dp"
android:gravity="top|right">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
<item
android:width="48dp"
android:height="8dp"
android:gravity="top|right">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
<item
android:width="8dp"
android:height="48dp"
android:gravity="bottom|left">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
<item
android:width="48dp"
android:height="8dp"
android:gravity="bottom|left">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
<item
android:width="8dp"
android:height="48dp"
android:gravity="bottom|right">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
<item
android:width="48dp"
android:height="8dp"
android:gravity="bottom|right">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>

关于安卓 : Border only on corners,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22877777/

27 4 0