Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a border on one edge of a view?

I have found that to add borders around views I can use the following code as a background for the view:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke android:width="1dp" android:color="#999999" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
    android:bottom="1dp" />
</shape>

But what if I want a border just for bottom, or top or right or left? I tried the following:

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

but when I set it as background

android:background="@drawable/my_border"

it draws the line at the middle of the view, so I have a strike-through effect. Is there any way I can draw this line at the bottom or at the top or make it vertical?

In WPF we have a relative coordinates for shapes, so I can offset lines as needed. Is there something similar on Android? If we don't have borders, at least we should have good line shape drawing tools, so we can draw borders as needed. Do Android developers plan to do something about it?

like image 724
JustAMartin Avatar asked Feb 01 '12 09:02

JustAMartin


1 Answers

For border line on the top or bottom of you view, you can check my previous answer here. It is a very simple way.

like image 146
MattZ Avatar answered Nov 10 '22 14:11

MattZ