Android Development Tutorial View Component Add border example _android

Source: Internet
Author: User

Add a border to textureview (a professional noun is a stroke), there are three solutions:

1. Set a 9 patch, right border, the middle is empty PNG.

2. Customize a view and draw a border with canvas.

3. Use the shapedrawable provided by Android to define a border.

Personal comparisons suggest a third way, because the third is written in XML, fast, resource-intensive, and less code-writing, easy to maintain.

Use the following methods:

1. Define a background.xml file.

Copy Code code as follows:

<?xml version= "1.0" encoding= "UTF-8"?>
<shape xmlns:android= "Http://schemas.android.com/apk/res/android" >
<stroke
Android:width= "2DP"
Android:color= "#0000AA"/>
</shape> <span></span>

2. Use it when setting the background of SRC in view.

Copy Code code as follows:

<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:gravity= "Center"
android:src= "@drawable/background"
android:padding= "2DP" >
<textureview
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"/>
<com.android.camera.ui.rotatelayout
Android:layout_width= "Wrap_content"
Android:layout_width= "Wrap_content" >
<textview
Android:layout_width= "Wrap_content"
Android:layout_width= "Wrap_content"
Android:textcolor= "#FFFFFF"
Android:textsize= "22SP"
android:background= "#0000000"/>
</com.android.camera.ui.RoateLayout>
</RelativeLayout>

The

Note is that I set the drawable for the Textureview parent container relativelayout and set padding.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.