我制作了 CustomUI.java 文件
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 显示空白布局并在第二个 n 关闭应用程序后显示错误。请帮我解决这个问题并在 android 中制作自定义 UI。
日志文件:http: //i.stack.imgur.com/o4L6o.jpg 或https://dl.dropboxusercontent.com/u/6608612/log.JPG