我已经为它创建了一个CustomView和一个xml布局,以便能够为我的Activity充气但是在运行Activity时永远不会得到任何布局,而是我得到一条错误消息,指示错误解析xml文件布局< / p>
这是我的活动 package com.example.myproject;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_view_layout);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
and this is my custom view
package com.example.myproject;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.View;
public class CustomView extends View {
public CustomView(Context context) {
super(context);
}
protected void onDraw(Canvas canvas){
canvas.drawColor(Color.GREEN);
}
}
and this is the layout i made for it
<com.exemple.myproject.CustomView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</com.exemple.myproject.CustomView>
and this is my Android Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myproject"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.myproject.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
答案 0 :(得分:0)
com.exemple.myproject.CustomView
可能是'example'而不是'exemple'。
如果您有视图的自定义参数,请添加xmlns:yourapp="http://schemas.android.com/apk/res-auto"
。