Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.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/4/video/2.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 安卓在其他图像上添加图像_Android_Imageview - Fatal编程技术网

Android 安卓在其他图像上添加图像

Android 安卓在其他图像上添加图像,android,imageview,Android,Imageview,我正在尝试使用ImageView(如果可能的话)以编程方式将一个图像添加到另一个图像上。我还需要能够使用它的吐温动画以后。我是一个业余程序员,对于这个基本的问题我感到非常抱歉。下面是我所拥有的,我很好地理解了编码的其他部分,但我以前从未做过任何图形化的工作,这就是为什么我在努力解决这个问题。我再次非常抱歉,因为我只是想学习一个新的编码领域 LinearLayout myLinearLayout; myLinearLayout = new LinearLayout(this);

我正在尝试使用ImageView(如果可能的话)以编程方式将一个图像添加到另一个图像上。我还需要能够使用它的吐温动画以后。我是一个业余程序员,对于这个基本的问题我感到非常抱歉。下面是我所拥有的,我很好地理解了编码的其他部分,但我以前从未做过任何图形化的工作,这就是为什么我在努力解决这个问题。我再次非常抱歉,因为我只是想学习一个新的编码领域

    LinearLayout myLinearLayout; 
    myLinearLayout = new LinearLayout(this); 
    ImageView myView = new ImageView(this); 
    myView.setScaleType(ImageView.ScaleType.FIT_XY);
    myView.setImageResource(R.drawable.base_image); 
    myView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    myLinearLayout.addView(myView);
    setContentView(myLinearLayout);

    LinearLayout imageLayout = new LinearLayout(this);
    imageLayout.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams vp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    imageLayout.setLayoutParams(vp);

    ImageView image = new ImageView(this);
    image.setImageResource(R.drawable.testicon);
    image.setLayoutParams(vp);

    myLinearLayout.addView(imageLayout);
    setContentView(myLinearLayout);

正如
Anggrayudi
所说,您应该使用
RelativeLayout
而不是首先使用
LinearLayout

然后您应该使用
LinearLayout
制作
vp
,以便将其分配给第二个图像

我对您的代码进行了如下编辑:

    RelativeLayout myRelativeLayout;
    myRelativeLayout = new RelativeLayout(this);
    ImageView myView = new ImageView(this);
    myView.setScaleType(ImageView.ScaleType.FIT_XY);
    myView.setImageResource(R.drawable.base_image);
    myView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
    myRelativeLayout.addView(myView);
    setContentView(myRelativeLayout);

    LinearLayout.LayoutParams vp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    ImageView image = new ImageView(this);
    image.setImageResource(R.drawable.testicon);
    image.setLayoutParams(vp);

    myRelativeLayout.addView(image);
请注意,我已经删除了一些不必要的行。
希望能有所帮助

使用
RelativeLayout
执行此操作。@Bill我为您的问题写了一个答案。请告诉我你的想法。