» 首頁 » 討論區 » Android程式設計 »畫布 頁面跳轉問題

畫布 頁面跳轉問題

發表人: Ray鴨鴨學語
積分: 28
發表時間: 2011-08-15 14:19:27
我不曉得問題是不是出在標出來那邊
因為平常的Activity都是用
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
就是我想從另一支Activity(從一個button)跳轉入這支畫布但是一直不行就算只是使用Button控制intent要轉入這支class也不行..
我的畫布那支Activity程式碼如下(太長所以只放厥得有問題部份)

android.widget.AdapterView.OnItemClickListener;
public class SignPNG extends Activity
{
MyView mv = null;
ListSDfiles lsdf = new ListSDfiles();
String STR = lsdf.STR;
String SD_path = lsdf.SD_path;
TextView txt = lsdf.txt;

//String str;
@Override
protected void onCreate(Bundle savedInstanceState)
{
這裡?->super.onCreate(savedInstanceState);
mv = new MyView(this);
setContentView(mv);
//
paint1 = new Paint();
paint1.setAntiAlias(true); //反鋸齒
paint1.setDither(true);
paint1.setColor(Color.BLACK);
paint1.setStyle(Paint.Style.STROKE);
paint1.setStrokeJoin(Paint.Join.ROUND);
paint1.setStrokeCap(Paint.Cap.ROUND);
paint1.setStrokeWidth(12);

//取得參數
Intent intent = this.getIntent();
Bundle bundle = intent.getExtras(); //取得Bundle
txt.setText(bundle.getString("STR")); //輸出Bundle內容
STR = bundle.getString("STR");
//bundle.putString("STR", "value2");
//intent.putExtras(bundle); //將name2放入Bundle
//SignPNG.this.setResult(Activity.RESULT_OK, intent); //回傳RESULT_OK
//SignPNG.this.finish(); //關閉Activity
}

private Path mPath;
private Bitmap mBitmap3;
private Canvas canvas1;
private Paint paint;//mBitmapPaint
private Paint paint1;//mPaint
public Bitmap backgroundBitmap = BitmapFactory.decodeFile(SD_path + STR);;
int width;
int height;
int color = Color.argb(0, 0, 0, 0);


public class MyView extends View
{
public MyView(Context c)
{
super(c);
發表人: Seachaos
積分: 2432
發表時間: 2011-08-15 20:40:27
您好
你的意思是說你要把Canvas轉給另外一個Acitivity用嗎?
還是?
發表人: Ray鴨鴨學語
積分: 28
發表時間: 2011-08-16 00:34:39
我想的架構是:

screen1的button點下後->進入screen2,此頁面設為畫布然後使用menu&submenu中的功能item,開啟sd卡裡的files



可是做好後卻無法從screen1的button進入screen2,不知道是因為將screen2設為畫布的關係還是有其他原因,我用myView來產生畫布的,之前設的Activity是用View來顯示畫面
會不會是setContentView(R.layout.main);

mv = new MyView(this);
setContentView(mv);
這兩個用法不同所以不能跳轉!?>"<


好多?????在頭上飛
發表人: Seachaos
積分: 2432
發表時間: 2011-08-16 16:20:49
Hi,
你的Screen1和Scenn2都是Activity嗎?

setContentView是設定Activiry的內容用的
可以用View或是Resource的Layout (就是R.layout.main之類的)

建議一個layout用一個Activity,不要在同個Activity內做setContentView的切換

所以你可以在Screen1用以下語法開起Screen2 (如果這兩個都是Activity)


[sea:javaCode]
Intent i = new Intent();
i.setClass(context, Screen2.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
[/sea]


對了, 要開起Activity必需要在AndroidManifest.xml內有註冊
(這點有時候大家會忘記)