Joks
Joks

Reputation: 420

Android TextView border with specific size

I need a border at the bottom, left and right of TextView, but for the left and right border only custom size of actual textview height, not the whole. Looks like this:

image

Could anyone explain how to implement it? At current moment I draw border at bottom, left and right using this code

<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>

Upvotes: 0

Views: 613

Answers (2)

Joks
Joks

Reputation: 420

Find a solution, this works for me

<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>

Upvotes: 0

santoXme
santoXme

Reputation: 802

You can directly give the padding to the layout in which you put the image and give background to the layout you will get border around the corner. And you also got custom border around the image.

<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" />

I am giving background to a image you can give image source.You can see How to can give padding and get what you want

Upvotes: 1

Related Questions