Android 仍使用XML视图时绘制位图
因此,我在程序中使用main.xml作为视图,但我仍然需要能够通过编程将BIMAP/drawables添加到屏幕上。有办法吗Android 仍使用XML视图时绘制位图,android,image,view,bitmap,drawable,Android,Image,View,Bitmap,Drawable,因此,我在程序中使用main.xml作为视图,但我仍然需要能够通过编程将BIMAP/drawables添加到屏幕上。有办法吗 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } 这有点像我的onCreate(但是有很多用于应用程序的代码) 是否有可能在我当前视图的顶部添加视图
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
这有点像我的onCreate(但是有很多用于应用程序的代码)
是否有可能在我当前视图的顶部添加视图或画布
我不熟悉android的位图和绘图功能,如果大家都知道这一点,我很抱歉,但我在任何地方都找不到合适的答案:p
谢谢,
Brandon在xml中为framelayout(或要放置视图的其他布局)创建一个Id 也许您可以使用类似以下内容的onCreate():
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Init the framelayout from xml by id
FrameLayout myFrameLayout = (FrameLayout) findViewById(R.id.myFrameLayout);
//Create a new ImageView
img_icon = new ImageView(this);
img_icon.setImageResource(R.drawable.icon);
img_icon.setAdjustViewBounds(true);
img_icon.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
//Add the newly created ImageView
myFrameLayout.addView(img_icon);
}