新建一个android项目

再添加一个class,如MyView,继承View或其它view,如TextView

package cn.zymk.test;import android.content.Context;import android.util.AttributeSet;import android.widget.TextView;public class MyView extends TextView {public MyView(Context context, AttributeSet attrs) {super(context, attrs);// TODO Auto-generated constructor stub}}

添加构造函数时要注意,必须添加public MyView(Context context, AttributeSet attrs)这个构造函数,否会报错

布局文件

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <cn.zymk.test.MyView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/hello" /></LinearLayout>

其实就是把TextView改成cn.zymk.test.MyView

需要其它的功能在MyView里添加就可以了

更多相关文章

  1. 【Android 性能优化】布局渲染优化 ( GPU 过度绘制优化总结 | CP
  2. Android 优化布局层次结构
  3. 谈谈android 布局 的优化
  4. android Activity线性布局和表格布局实例讲解
  5. 【ALearning】第四章 Android Layout组件布局(一)
  6. 利用BeautifulSoup的find_all()函数查找某个标签且该标签某属性

随机推荐

  1. android中HttpURLConnection调用getRespo
  2. 初识ProgressBar
  3. android ndk Hello World
  4. Android读取xxx.properties配置文件中文
  5. Android使用HttpURLConnection访问网络
  6. 保持在底部的按钮栏,上面是滚动的ScrollVi
  7. Android(安卓)Socket&Cocos2dx的资料
  8. android studio 项目的版本问题
  9. Ubuntu下建立Android开发环境
  10. 【原版的:参赛作品】窥秘懒---android打开