* "bouton"ボタンを押した後、 "maview"という名前のパネルに線を描きたいと思います。しかし、私のプログラムはレイアウト全体に線を引いて、ボタンは消えます。 アイデアはありますか?ありがとうございました! * 私のコード:パネル上での描画
package esslineter.pack;
import android.app.Activity;
import android.os.Bundle;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
import android.widget.TextView;
import android.content.Context;
public class EsslineterActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView (R.layout.main);
}
public void bouton (View view)
{
maView cv=new maView(this);
setContentView(cv); cv.invalidate();
}
public class maView extends View
{
public maView(Context context)
{
super(context);
}
@Override
protected void onDraw(Canvas canvas)
{
Paint p = new Paint();
p.setColor(Color.WHITE);
p.setStyle(Paint.Style.STROKE);
p.setStrokeWidth(3);
canvas.drawColor(Color.BLUE);
canvas.drawLine(0,0, 100, 100, p);
}
}
}
私のレイアウト:ここで
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/bouton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="bouton"
android:text="draw line" />
<View class="EsslineterActivity.maView"
android:id="@+id/surfaceView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.86" />
</LinearLayout>
ありがとう、ありがとう、あなたが言うことを正確に行うと、私は "キャッチされていない例外(グループ= 0x40015560)で終了スレッド" ... – user1098281
あなたは完全なエラーログを提供することはできますか? – Jin35
12-16 14:23:28.692:I /プロセス(652):送信信号。 PID:652 SIG:9 12-16 14:24:31.572:D/AndroidRuntime(702):VMをシャットダウンする 12-16 14:24:31.572:W/dalvikvm(702):threadid = 1:未知の例外(グループ= 0x40015560) 12-16 14:24:31.682:E/AndroidRuntime(702):致命的な例外:メイン 12-16 14:24:31.682:E/AndroidRuntime(702):java.lang.IllegalStateException :アクティビティのメソッドを実行できませんでした 12-16 14:24:31.682:E/AndroidRuntime(702):\t android.view.View $ 1.onClick(View.java:2144) – user1098281