簡體   English   中英

如何通過imageview投射視圖將背景設置為imageView?

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

我想將圖像放到圖像上,並且我有一個代碼,其中View由類型為ImageView類型轉換為v.name “ dropped”,並且該視圖將在其他名為“ droptarget”的ImageView上顯示為背景,但是無法發生,請zzzz告訴我一個解法。 我的代碼在這里:

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

您應該給我們更多有關代碼的信息,但是無論如何我都會提出一些建議。

我認為您是在null對象上調用setBackgroundResource。 所以你錯了在下一行

ImageView dropTarget = (ImageView) v;

可能沒有稱為“ v”的視圖。 也許您應該改變它?

我相信您正在尋找ImageView.setImageResource 您也可以設置backgroundImage,但是最佳實踐是使用setimageResource。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM