您的位置:首页 > 移动开发 > Android开发

android 在布局中使用自定义属性

2016-10-13 11:16 246 查看
1.在布局中使用自己的自定义属性的时候,首先要在布局中设置声明:

xmlns:app=”http://schemas.android.com/apk/res-auto”

2.声明完成之后就可以直接使用自己定义的属性了。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:background="#ffffff"
android:orientation="vertical"
android:layout_height="match_parent">

<!--绘画一个圆形图片-->
<com.zhjy.measureview.CircleView
android:layout_width="wrap_content"
android:background="#000000"
android:layout_margin="20dp"
android:padding="20dp"
app:circle_color="@color/colorAccent"
android:layout_height="100dp" />

</LinearLayout>


3.自定义的attrs属性如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="CircleView">
<attr name="circle_color" format="color"/>
</declare-styleable>
</resources>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐