android開發(fā)教程之view組件添加邊框示例
給TextureView添加邊框(專業(yè)名詞為描邊),有三種解決方案:
1.設(shè)置一個(gè)9 patch 的,右邊框,中間是空的PNG。
2.自定義一個(gè)View,用Canvas畫個(gè)邊框。
3.用Android提供的ShapeDrawable來定義一個(gè)邊框。
個(gè)人比較建議采用第三種方式,原因是因?yàn)榈谌N只要寫XML,速度快,占用資源小,代碼編寫量也少,便于維護(hù)。
使用方法如下:
1.定義一個(gè)background.xml文件。
<?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.在View的src設(shè)置背景時(shí)使用就可以了。
<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>
需要注意的是我給TextureView的父容器RelativeLayout設(shè)置了Drawable,并設(shè)置了Padding。
相關(guān)文章
Android實(shí)現(xiàn)EditText的富文本編輯
這篇文章主要介紹了Android實(shí)現(xiàn)EditText的富文本編輯,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08安卓(Android)實(shí)現(xiàn)3DTouch效果
3DTouch是什么效果的大家應(yīng)該都知道了。本文將介紹在Android中如何實(shí)現(xiàn)3DTouch的效果,有需要的可以參考學(xué)習(xí)。2016-08-08Android同步屏障機(jī)制sync barrier實(shí)例應(yīng)用詳解
這篇文章主要介紹了Android同步屏障機(jī)制sync barrier實(shí)例應(yīng)用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2023-02-02基于Android實(shí)現(xiàn)答題倒計(jì)時(shí)功能
這篇文章主要介紹了基于Android實(shí)現(xiàn)答題倒計(jì)時(shí)功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01android中Bitmap用法(顯示,保存,縮放,旋轉(zhuǎn))實(shí)例分析
這篇文章主要介紹了android中Bitmap用法,以實(shí)例形式較為詳細(xì)的分析了android中Bitmap操作圖片的顯示、保存、縮放、旋轉(zhuǎn)等相關(guān)技巧,需要的朋友可以參考下2015-09-09Android實(shí)現(xiàn)自動(dòng)填充短信驗(yàn)證碼
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)自動(dòng)填充短信驗(yàn)證碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-05-05全面解析Android系統(tǒng)指紋啟動(dòng)流程
這篇文章主要介紹了全面解析Android系統(tǒng)指紋啟動(dòng)流程,對(duì)Android啟動(dòng)原理感興趣的同學(xué)可以參考下2021-04-04Android Studio打包APK文件具體實(shí)現(xiàn)步驟解析
這篇文章主要介紹了Android Studio打包APK文件具體實(shí)現(xiàn)步驟解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-11-11