zoukankan      html  css  js  c++  java
  • 一手遮天 Android

    项目地址 https://github.com/webabcd/AndroidDemo
    作者 webabcd

    一手遮天 Android - view(自定义): 自定义控件的自定义属性

    示例如下:

    /view/custom/CustomView4Demo.java

    /**
     * 演示自定义控件的自定义属性的使用,自定义控件的实现代码参见 view/custom/CustomView4.java
     */
    
    package com.webabcd.androiddemo.view.custom;
    
    import androidx.appcompat.app.AppCompatActivity;
    import android.os.Bundle;
    
    import com.webabcd.androiddemo.R;
    
    public class CustomView4Demo extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_view_custom_customview4demo);
        }
    }
    
    

    /layout/activity_view_custom_customview4demo.xml

    <?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:layout_height="match_parent"
        android:orientation="vertical">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="运行结果请见 Logcat 日志" />
    
        <!--
            演示自定义控件的自定义属性的使用
            声明命名空间 xmlns:app="http://schemas.android.com/apk/res-auto" 后,在 <com.webabcd.androiddemo.view.custom.CustomView4 /> 中可以通过 app:attr01, app:attr02 之类的来设置自定义属性
    
            android:text - 设置自定义控件引用的系统自带的属性
            app:attr05 - 设置百分数类型的属性
            app:attr07 - 设置尺寸类型的属性
            app:attr09 - 设置 flag 类型的枚举
            app:attr11 - 此属性支持多个类型
        -->
        <com.webabcd.androiddemo.view.custom.CustomView4
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="i am webabcd"
            app:attr01="abc"
            app:attr02="100"
            app:attr03="true"
            app:attr04="0.5"
            app:attr05="50%"
            app:attr06="#ff0000"
            app:attr07="10sp"
            app:attr08="enum3"
            app:attr09="flag1|flag4|flag5"
            app:attr10="@drawable/img_sample_son"
            app:myAttr01="webabcd" />
    
        <com.webabcd.androiddemo.view.custom.CustomView4
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:attr11="green" />
    
        <com.webabcd.androiddemo.view.custom.CustomView4
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:attr11="@drawable/img_sample_son" />
    
    </LinearLayout>
    
    

    项目地址 https://github.com/webabcd/AndroidDemo
    作者 webabcd

  • 相关阅读:
    windows命令提示符常用命令
    JAVA中定义不同进制整数
    进制转换
    win10配置jdk环境变量
    AI Gossip
    搜狗大数据总监、Polarr 联合创始人关于深度学习的分享交流 | 架构师小组交流会
    后端渲染实践——看掘金社区是如何实践的
    谢孟军:The State of Go | ECUG Con 精粹系列
    让你的 CDN 费用省 50% 以上!图片瘦身的正确姿势
    七牛云大数据平台建设实践
  • 原文地址:https://www.cnblogs.com/webabcd/p/android_view_custom_CustomView4Demo.html
Copyright © 2011-2022 走看看