main.xmlファイルの下部にカスタムビューを配置したいのですが、以下は私のActivityクラスとカスタムビュークラス(game.java)です:ゲームビューをmain.xmlファイルの下部に表示したい。その方法を教えてください....main.xmlにレイアウトを設定してから、そのレイアウトにカスタムビューを表示するのが目的だと思います。私の主な目的は、カスタムビューを下部に表示することです。 main.xmlレイアウトの半分。助けてください!!!!!
// LearningActivity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//For my button class
/*
MyButton myb = (MyButton)findViewById(R.id.mybutton1);
myb.setText("Hello Students");
myb.setTextSize(40);
**/
//For custom view
setContentView(R.layout.main);
RelativeLayout r=(RelativeLayout) findViewById(R.id.relative1);
g=new game(this,null);
ViewGroup vgroup=(ViewGroup) findViewById(R.id.main);
vgroup.addView(g);
Thread mythread=new Thread(new UpdateThread());
mythread.start();
}
Game.java(カスタムビュー)
public class game extends View{
private Bitmap image;
private Paint paint;
private int x=0;private int baseY = 250;
public game(Context context,AttributeSet attrs) {
super(context,attrs);
this.inflate(context, R.layout.example, null);
image=Bitmap.createBitmap(BitmapFactory.decodeResource(this.getResources(),R.drawable.ic_launcher));
paint =new Paint();
paint.setColor(Color.BLUE);
}
public View getlay (RelativeLayout r)
{
return r;
}
public void onDraw(Canvas canvas)
{
super.onDraw(canvas);
canvas.drawLine(90, baseY,200,baseY, paint);
canvas.drawLine(125,baseY,125,baseY-100,paint);
canvas.drawLine(110,baseY,125,baseY-15,paint);
..................
}
)。
LOGCAT:
06-28 22:43:59.757: E/AndroidRuntime(505): FATAL EXCEPTION: main
06-28 22:43:59.757: E/AndroidRuntime(505): java.lang.RuntimeException: Unable to start activity ComponentInfo{your.com.learn/your.com.learn.LearningActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class your.com.learn.game
06-28 22:43:59.757: E/AndroidRuntime(505): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
06-28 22:43:59.757: E/AndroidRuntime(505): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-28 22:43:59.757: E/AndroidRuntime(505): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-28 22:43:59.757: E/AndroidRuntime(505): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-28 22:43:59.757: E/AndroidRuntime(505): at android.os.Handler.dispatchMessage(Handler.java:99)
06-28 22:43:59.757: E/AndroidRuntime(505): at android.os.Looper.loop(Looper.java:123)
06-28 22:43:59.757: E/AndroidRuntime(505): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-28 22:43:59.757: E/AndroidRuntime(505): at java.lang.reflect.Method.invokeNative(Native Method)
06-28 22:43:59.757: E/AndroidRuntime(505): at java.lang.reflect.Method.invoke(Method.java:507)
06-28 22:43:59.757: E/AndroidRuntime(505): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-28 22:43:59.757: E/AndroidRuntime(505): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-28 22:43:59.757: E/AndroidRuntime(505): at dalvik.system.NativeStart.main(Native Method)
06-28 22:43:59.757: E/AndroidRuntime(505): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class your.com.learn.game
06-28 22:43:59.757: E/AndroidRuntime(505): at android.view.LayoutInflater.createView(LayoutInflater.java:508)
06-28 22:43:59.757: E/AndroidRuntime(505): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
06-28 22:43:59.757: E/AndroidRuntime(505): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
06-28 22:43:59.757: E/AndroidRuntime(505): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
06-28 22:43:59.757: E/AndroidRuntime(505): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-28 22:43:59.757: E/AndroidRuntime(505): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
06-28 22:43:59.757: E/AndroidRuntime(505): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
06-28 22:43:59.757: E/AndroidRuntime(505): at android.app.Activity.setContentView(Activity.java:1657)
06-28 22:43:59.757: E/AndroidRuntime(505): at your.com.learn.LearningActivity.onCreate(LearningActivity.java:38)
06-28 22:43:59.757: E/AndroidRuntime(505): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-28 22:43:59.757: E/AndroidRuntime(505): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
06-28 22:43:59.757: E/AndroidRuntime(505): ... 11 more
06-28 22:43:59.757: E/AndroidRuntime(505): Caused by: java.lang.NoSuchMethodException: game(Context,AttributeSet)
06-28 22:43:59.757: E/AndroidRuntime(505): at java.lang.Class.getMatchingConstructor(Class.java:643)
06-28 22:43:59.757: E/AndroidRuntime(505): at java.lang.Class.getConstructor(Class.java:472)
06-28 22:43:59.757: E/AndroidRuntime(505): at android.view.LayoutInflater.createView(LayoutInflater.java:480)
06-28 22:43:59.757: E/AndroidRuntime(505): ... 21 more