所以基本上我想使用xml布局,但是我也想要可以在其中执行图形的画布。我所做的就是在我的xml布局中进行查看,如下所示。然后在我的应用程序中,我使视图绘制了画布,但是它不起作用。我不确定解决这个问题的方法是完全错误的还是什么。因此,请看一下我的代码,并告诉我您是否可以快速解决问题,或者是否有更好的方法。在此先感谢,我非常感谢。
<?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" >
<Button
android:id="@+id/bTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<View
android:id="@+id/vMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是xml布局
package sm.view.test;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
public class ViewActivity extends Activity implements OnTouchListener {
/** Called when the activity is first created. */
View v;
Button b;
boolean isRun =true;
SurfaceHolder ourHolder;
Thread ourThread;
Canvas …Run Code Online (Sandbox Code Playgroud) 我有一个单词数组,我想在单击一个按钮后在文本视图中将单词数组打印到屏幕上.我使用for循环遍历整个列表,然后设置文本,但我不断得到一个错误加上它只会替换最后一个值,所以它不会打印整个数组.如果有人可以向我解释如何做一个g.drawSting()但是android版本会很棒.我的代码rt现在不是和我在一起,但它类似于: - 我是android btw的初学者,可能可以通过这个问题告诉你.
public void onCreate(Bundle savedInstanceState)
{
//code for a button just being pressed{
//goes to two methods to fix the private array{
for(int y=0; y<=array.size()-1; y++){
textArea.setText(aarray.get(y)); //prints all strings in the array
}
}
}
Run Code Online (Sandbox Code Playgroud)