我开始一个测试项目只是为了解决这个问题.没有对main.xml的更改.我想创建一个小部件大小的ImageView(80x100),其中包含从TextView转换的位图.是的,这听起来非常迂回,但这只是为了测试; 最后,我希望ImageView有一个背景图像和多个TextViews.我不确定我做错了什么,但没有任何东西被推到屏幕上.
声明TextView/ImageView并在构造函数中传递"this"是一个问题吗?这是我的layoutParams的问题吗?这是代码:
package com.doaf.testproject;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class TestProject extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(80, 100);
tv.setLayoutParams(layoutParams);
tv.setText("testing 1 2 3");
tv.setTextColor(0xFFFFFF);
tv.setBackgroundColor(0x555555);
Bitmap testB;
testB = loadBitmapFromView(tv);
ImageView iv = new ImageView(this);
iv.setLayoutParams(layoutParams);
iv.setBackgroundColor(0x555555);
iv.setImageBitmap(testB);
setContentView(iv);
}
public static Bitmap loadBitmapFromView(View …Run Code Online (Sandbox Code Playgroud)