我之前曾問過這個項目,但我遇到了新的問題和想要分享的新想法。Android:顯示位圖
我想繪製大量的隨機間隔相同的圖形。
下面是過渡到第二活動代碼的第一個活動碼:
package com.category.tap;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
public class TitleActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_title);
ImageButton switchButton = (ImageButton) findViewById(R.id.play);
switchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(TitleActivity.this, GameActivity.class);
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.title, menu);
return true;
}
}
第二個活動的代碼是:
package com.category.tap;
import android.app.Activity;a
import android.os.Bundle;
import android.view.Menu;
public class GameActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.game, menu);
return true;
}
}
被覆蓋的onDraw:
package com.category.tap;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.View;
public class DrawV extends View {
public DrawV(Context context){
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Bitmap bit_dot = BitmapFactory.decodeResource(getResources(), R.drawable.dot_catch);
canvas.drawBitmap(bit_dot, 100, 100, null);
canvas.drawBitmap(bit_dot, -30, -30, null);
}
}
最後,遊戲活動的佈局:
<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=".GameActivity"
android:text="@string/ShowText" >
<View
class="com.category.tap.DrawV"
android:layout_width="100dp"
android:layout_height="100dp" />
</RelativeLayout>
問題:單擊第一個活動的佈局中的按鈕後,轉換到第二個屏幕是白色屏幕。此外,在logcat屏幕的底部,底部M的波動範圍從300M的80M到300M的110。此外,應列出所列出的遊戲佈局中的哪些文件夾名稱或期限之間的術語用於此值? 100,100和-30,-30圖形值只是測試邊界( - )。此外,Game Layout中的android:text =「@ string/ShowText」也不會顯示。
唯一的紅色logcat的條目是間歇性的
03-05 13:27:52.020: E/KINETO(243): KLOG082- 01 00 09 02 00 00 00 00
03-05 13:27:55.020: E/KINETO(243): KLOG082- 01 00 09 02 00 00 00 00
etc.
感謝您的幫助。我很困難。
@Melvelde嘿,說了自己的情況下,更好的...希望... – user963070