一、最简单的自定义View,什么都不显示,但是有View的特性
com.cctvjiatao.customview.MainActivity
package com.cctvjiatao.customview;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
com.cctvjiatao.customview.v1.CustomView1
package com.cctvjiatao.customview.v1;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
/**
* @作者: jiatao
* @修改时间:2016-3-11 上午7:58:10
* @包名:com.cctvjiatao.customview.v1
* @文件名:CustomView1.java
* @版权声明:www.cctvjiatao.com
* @功能: 最简单的自定义View,什么都不显示,但是有View的特性
*/
public class CustomView1 extends View {
public CustomView1(Context context) {
super(context);
}
public CustomView1(Context context, AttributeSet attrs) {
super(context, attrs);
}
}
activity_main.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.cctvjiatao.customview.v1.CustomView1
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00ff00" >
</com.cctvjiatao.customview.v1.CustomView1>
</FrameLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cctvjiatao.customview"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="