【发布时间】:2014-03-05 19:48:08
【问题描述】:
我以前问过这个项目,但我遇到了新问题和新想法,我想分享一下。
我正在尝试以随机间隔绘制大量相同的图形。
这是转换到第二个活动代码的第一个活动代码:
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 图形值只是测试边界 (-)。此外,游戏布局中的 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 嘿,更好地说明我的情况......希望......
标签: java android layout view ondraw