安卓 - 水平线上的形状

5

我有一个 xml 文件,其中我在 TextViews 之间添加了一条 Horizontal Line。我为分隔符添加了一个 Shape,但我看不到任何变化。

main_activity.xml :

<TextView
    android:id="@+id/title"
    android:layout_width="match_parent"
    android:layout_height="20dp"
    android:text="HELLO"
    android:textColor="@android:color/black" />

<View
    android:id="@+id/vVerticalLine"
    android:background="@drawable/horizontal_shape"
    android:layout_width="match_parent"
    android:layout_marginLeft="50dp"
    android:layout_marginRight="20dp"
    android:layout_below="@+id/title"
    android:layout_height="10dp" />

<TextView
    android:id="@+id/txt"
    android:layout_width="match_parent"
    android:layout_height="20dp"
    android:text="HELLO"
    android:textColor="@android:color/black" />

以下是我的horizontal_shape.xml文件:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">

    <corners
        android:bottomLeftRadius="5dp"
        android:bottomRightRadius="5dp"
        android:topLeftRadius="5dp"
        android:topRightRadius="5dp" />

    <stroke
        android:color="#000000" />

</shape>

例如,我需要:
例如,您可以使用以下代码将文本框添加到 HTML 中:
``` ```
该代码将创建一个名为“myText”的文本输入框,用户可以在其中输入文本。

main_activity.xml 的背景是白色的。 - user4501847
2
请使用 <solid> 而非 stroke。 - Harin
@ Harry。你的帮助真是太好了。回答问题以便投票。谢谢。 - user4501847
1个回答

8
<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <corners
        android:bottomLeftRadius="5dp"
        android:bottomRightRadius="5dp"
        android:topLeftRadius="5dp"
        android:topRightRadius="5dp" />
    <size
        android:height="6dp" />
    <solid
        android:color="#daa520" />

</shape>

这个方法对我很有效,而其他 Stack Overflow 上的解决方案都没有帮助。谢谢! - Sufian

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接