通过扩展视图创建自定义视图并将其排列在布局中。现在尝试将位图设置为自定义视图背景但未获得如何操作请求帮助。 在这里我正在添加我的主要课程
public class CreatePeeqsActivity extends Activity implements OnClickListener {
private ImageView ivImage, ivCountTimer;
private TextView tvUndo, tvNext;
private ImageView ivFont, ivSquare, ivRectangle, ivLine, ivCircle, ivOval;
PhotoSortrView photoSorter;
final Context context = this;
//EditText editTextAddText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
photoSorter = new PhotoSortrView(this);
setContentView(R.layout.activity_create_peeqs);
getIds();
byte[] byteArray = getIntent().getByteArrayExtra("BitmapImage");
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0,
byteArray.length);
}
答案 0 :(得分:1)
只需将位图转换为drawable并将其设置为视图的背景。
byte[] byteArray = getIntent().getByteArrayExtra("BitmapImage");
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0,
byteArray.length);
Drawable d = new BitmapDrawable(getResources(),bmp);
photoSorter.setBackground(d);
//or
photoSorter.setBackgroundDrawable(d);