Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 仍使用XML视图时绘制位图_Android_Image_View_Bitmap_Drawable - Fatal编程技术网

Android 仍使用XML视图时绘制位图

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(但是有很多用于应用程序的代码) 是否有可能在我当前视图的顶部添加视图

因此,我在程序中使用main.xml作为视图,但我仍然需要能够通过编程将BIMAP/drawables添加到屏幕上。有办法吗

 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);

}