具有特定大小的Android TextView边框

时间:2015-12-01 14:04:52

标签: android textview border

我需要在TextView的底部,左侧和右侧有一个边框,但是对于左右边框,只有实际textview高度的自定义大小,而不是整个。 看起来像这样:

image

任何人都可以解释如何实现它吗? 目前,我使用此代码在底部,左侧和右侧绘制边框

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape android:shape="rectangle">
        <solid android:color="@color/white" />
    </shape>
</item>

<item
    android:bottom="1px"
    android:left="1px"
    android:right="1px"
    android:top="-2dp">
    <shape android:shape="rectangle">
        <stroke
            android:width="1dp"
            android:color="@color/grey_20" />
        <solid android:color="@null" />
    </shape>
</item>

2 个答案:

答案 0 :(得分:1)

您可以直接将填充物添加到放置图像的布局中,并为布局提供背景。 而且你还有图像周围的自定义边框。

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="10dp"
android:paddingTop="20dp">
<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff" />

我为您提供图片来源的图片提供了背景资料。You can see How to can give padding and get what you want

答案 1 :(得分:0)

找到解决方案,这对我有用

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item>
    <shape>
        <solid android:color="@color/line_grey" />
    </shape>
</item>

<item
    android:bottom="1dp"
    android:left="1dp"
    android:right="1dp">
    <shape>
        <solid android:color="@color/white" />
    </shape>
</item>

<item android:bottom="8.0dp">
    <shape>
        <solid android:color="@color/white" />
    </shape>
</item>