Reputation: 21
I have been searching for similar problems/situations but to no anvil, I find myself looking for your help.
I have a good general understanding of Androids interface system through XML. I want to set a border on all sides, left, right, bottom and top of an image-view.
XML Code:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="2dp"
android:background="#555555">
<ImageView
android:id="@+id/imageview_de_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0.1dp"
android:background="#ffffff"
android:contentDescription="@string/imageview"
android:src="@drawable/ic_action_previous_item" />
</RelativeLayout>
So I understand that the margin property separates views by the defined unit. In this case I have it set to 0.1dp of the its parent view which has a background color of #555555. The left, top, and right borders are present, but the bottom border line is not...
Can anyone point me to what I am doing wrong or my misunderstanding?
Upvotes: 1
Views: 3702
Reputation: 10076
above all ans may helps you lot but there is a tool for this use that in future
and Ans to your question create image_border.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid
android:color="#D4D4D4"/>
<size
android:width="202dp"
android:height="60dp"/>
<stroke
android:width="4dp"
android:color="#8E939C"/>
</shape>
and apply to your ImageView
as background
Upvotes: 1
Reputation: 1684
Put the following code in XML in your drawable folder and name it myImageView
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke android:width="1dp" android:color="#000000" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
android:bottom="1dp" />
</shape>
And specify the drawable of your ImageView in your layout xml:
<ImageView android:id="@+id/my_image"
android:layout_width="100dp" android:layout_height="100dp"
android:src="@drawable/myImageView"
/>
For more you can check this link
Upvotes: 0
Reputation: 436
Use this code in xml file and add this xml file as your imageview background
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#222222" />
<stroke android:width="1dp" android:color="#ffffff" />
<padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp" /></shape>
Upvotes: 3
Reputation: 3663
Use this drawable as your image view background.
image_border.xml
<?xml version="1.0" encoding="UTF-8"?>
<solid android:color="@color/color_transparent" />
<stroke
android:width="1dp"
android:color="#ff6600" />
<corners android:radius="2dp" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
Upvotes: 2