ShapeDrawable顶部有黑色边框

时间:2015-09-02 02:27:29

标签: android xml shapedrawable

我正在尝试为表格单元格的背景创建一个ShapeDrawable。目前,我有一个带有1px黑色边框的白色矩形:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape= "rectangle"  >
    <solid android:color="#fff"/>
    <stroke android:width="1dp"  android:color="#000"/>
</shape>

我想得到这个确切的东西,但只有沿着形状的顶部和底部的边框。有人可以展示如何执行此操作,或链接到解释如何使用ShapeDrawable的页面?谢谢!

1 个答案:

答案 0 :(得分:0)

你使用图层列表来看看这个

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <solid android:color="#FF0000" />
    </shape>
</item>
<item android:top="5dp" android:bottom="5dp">
    <shape android:shape="rectangle">
        <solid android:color="#000000" />
    </shape>
</item>

或者你可以像这样在你的布局上做一个填充

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f00">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff"
    android:layout_marginTop="5dp"android:layout_marginBottom="5dp"></LinearLayout>

</LinearLayout>
相关问题