简体   繁体   English

如何通过imageview投射视图将背景设置为imageView?

[英]how to set background to imageView by imageview casted View?

I want to drop an image over an image and I have a code in which View is type casted by ImageView with v.name 'dropped' and this view will display on other ImageView named 'droptarget' as background but cant happend, plzz tell me a solution. 我想将图像放到图像上,并且我有一个代码,其中View由类型为ImageView类型转换为v.name “ dropped”,并且该视图将在其他名为“ droptarget”的ImageView上显示为背景,但是无法发生,请zzzz告诉我一个解法。 my code is here.: 我的代码在这里:

 case DragEvent.ACTION_DROP:

           //handle the dragged view being dropped over a target view

            View view = (View) event.getLocalState();

            //stop displaying the view where it was before it was dragged

            view.setVisibility(View.INVISIBLE);

            //view dragged item is being dropped on

            ImageView dropTarget = (ImageView) v;

            //view being dragged and dropped

            ImageView dropped = (ImageView) view;

            //it give me error in this line

            **dropTarget.setBackgroundResource(dropped);**

You should give us more info about the code but anyway I'm going to suggest something. 您应该给我们更多有关代码的信息,但是无论如何我都会提出一些建议。

I think you're calling setBackgroundResource on a null object. 我认为您是在null对象上调用setBackgroundResource。 So you're mistake is on the next line 所以你错了在下一行

ImageView dropTarget = (ImageView) v;

There probably isn't a view called "v". 可能没有称为“ v”的视图。 Maybe you should change that? 也许您应该改变它?

I believe you are looking for ImageView.setImageResource . 我相信您正在寻找ImageView.setImageResource You can also set the backgroundImage, but best practice is to use setimageResource. 您也可以设置backgroundImage,但是最佳实践是使用setimageResource。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM