时间:2021-05-20
给TextureView添加边框(专业名词为描边),有三种解决方案:
1.设置一个9 patch 的,右边框,中间是空的PNG。
2.自定义一个View,用Canvas画个边框。
3.用Android提供的ShapeDrawable来定义一个边框。
个人比较建议采用第三种方式,原因是因为第三种只要写XML,速度快,占用资源小,代码编写量也少,便于维护。
使用方法如下:
1.定义一个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设置背景时使用就可以了。
复制代码 代码如下:
<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设置了Drawable,并设置了Padding。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文简单讨论以后Android游戏引擎模板的架构问题。在Android游戏开发教程之二:View类与SurfaceView类中我们已经谈到,SurfaceVie
本文实例讲述了ZendFramework入门教程之Zend_View组件用法。分享给大家供大家参考,具体如下:Zend_View组件可以实现MVC模式中视图部分
本文实例讲述了ZendFramework教程之视图组件Zend_View用法。分享给大家供大家参考,具体如下:Zend_View是ZendFramework的视
相关文章:微信小程序教程之wxapp视图容器swiper微信小程序教程之wxapp视图容器scroll-view微信小程序教程之wxapp视图容器view微信小
相关文章:微信小程序教程之wxapp视图容器swiper微信小程序教程之wxapp视图容器scroll-view微信小程序教程之wxapp视图容器viewscr