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

  • 相关阅读:
    C++ CGI Helloword
    国内外12个免费域名解析服务网站推荐
    U制作LFS linux
    LFS 中文版手册发布:如何打造自己的 Linux 发行版
    windows下的BT服务器搭建方案
    Linux下搭建BT服务器
    Codeforces 842B Gleb And Pizza【几何,水】
    Codeforces 842A Kirill And The Game【暴力,水】
    Wannafly模拟赛 A.矩阵(二分答案+hash)
    数据结构学习笔记【持续更新】
  • 原文地址:https://www.cnblogs.com/webabcd/p/android_view_custom_CustomView4Demo.html
Copyright © 2011-2022 走看看