zoukankan      html  css  js  c++  java
  • Android: Custom View和include标签的区别

    Custom View, 使用的时候是这样的:

        <com.example.home.alltest.view.MyCustomView
            android:id="@+id/customView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </com.example.home.alltest.view.MyCustomView>

    使用的时候是这样的:

    _customView = (MyCustomView)findViewById(R.id.customView1);
    _customView.setText("What's", "UP?");

    但是include是一个表情,在布局中使用的时候是这样的:

    <include layout="@layout/view_my_custom"
            android:id="@+id/customView1" />

    这个表情将会被layout属性制定的布局文件替换掉,所以这里的include只是view_my_custom布局文件的RelativeLayout占位符。

    在代码中使用的时候是这样的:

    RelativeLayout _relativeLayout = (RelativeLayout)findViewById(R.id.customView1);
    TextView textWorld = (TextView)_relativeLayout.findViewById(R.id.txtWorld);

    区别就是,第一种方法可以直接findViewById之后当做你的自定义类来使用。而include标签只是占位符,在编译的时候这里就变成了你的自定义空间的那一堆各种Layout了。所以在使用的时候只能在脑中把被替换掉的layout文件再补回来。

  • 相关阅读:
    shell加密为二进制可执行文件
    lua自写限制并发访问模块
    centos虚拟机中挂新硬盘
    lua文件修改为二进制文件
    常用一些命令方法
    常用问题处理方法
    CVE-2010-3333
    Kernel Stack Overflow(转)
    NULL Pointer Dereference(转)
    Linux内核漏洞利用-环境配置(转)
  • 原文地址:https://www.cnblogs.com/sunshine-anycall/p/4819475.html
Copyright © 2011-2022 走看看