我做CustomUI.java文件使得Custome UI(通過擴展視圖)
public class CustomUI extends View {
Bitmap icon;
float left=0;
public CustomUI(Context context) {
super(context);
icon=BitmapFactory.decodeResource(getResources(), R.drawable.icon);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
canvas.drawBitmap(icon, left, 0, null);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(250, 100);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if(event.getAction()==event.ACTION_SCROLL){
left=event.getX();
}
if(left>=200){
//do some activity;
}
return true;
}
}
我做了佈局custom_ui.xml文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".CustomUI" >
<com.example.missedcall.CustomUI
android:id="@+id/single_spinner"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</com.example.missedcall.CustomUI>
</RelativeLayout>
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.missedcall"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.missedcall.CustomUI"
android:label="@string/title_activity_custom_ui" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
當我顯示圖形佈局顯示我很好,但是當我運行它時, 其運行n顯示空白布局並在第二次顯示後顯示錯誤失去應用程序 請幫我解決這個問題,並在android中製作自定義UI。
日誌文件: http://i.stack.imgur.com/o4L6o.jpg 或https://dl.dropboxusercontent.com/u/6608612/log.JPG
它可能是在構造函數?儘量不帶參數... –