android - 将相同的 ImageView 多次添加到布局

标签 android layout imageview duplicates clone

我想在运行时多次将相同的 ImageView 添加到我的布局中。我尝试定义 ImageView(大小、位置、...)并使用 LAYOUT.addView(IMAGEVIEW) 添加它。但是,如果我尝试第二次添加它(同一布局中的不同位置),它就不起作用。似乎不能将位图的相同引用 ID 添加到布局中两次。

我发现了问题。我的位图太大了。如果我减小位图的大小,它就可以工作。不管怎样,谢谢你的帮助。

最佳答案

这门课应该有帮助:

public class MyImageView implements Cloneable {

public MyImageView(Context ctx){
    super(ctx);
}
public Object clone(){
    try{
        MyImageView obj = new MyImageView(this.getContext());
        obj.setImageDrawable(this.getDrawable());
        obj.setScaleType(this.getScaleType());
        try{
            obj.setLayoutParams(this.getLayoutParams());    
        }catch(Exception e){

        }

        obj.setId((int)(Math.random() * 100));

    } catch (CloneNotSupportedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return obj;
}

关于android - 将相同的 ImageView 多次添加到布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7139791/

相关文章:

layout - flutter |如何在任何叠加层之上显示 AlertDialog?

java - android 覆盖流高度

swift - 将图像数据从一个 View Controller 传递到另一个 View Controller

Android EPUBLIB 读取/加载内容

android - "ERROR getting ' 安卓 :icon ' attribute: attribute is not a string value" when trying to upload to the Android Market

css - 嵌套的 div 同样长

android - 如何从另一个线程(Android 处理程序)在 ImageView 中显示位图

iPhone/Android/BlackBerry 上的 jQuery

android - 如何在 Scroll 的 CoordinatorLayout 中隐藏 FloatingActionMenu?

android - 如何在android gridview上进行 ImageView 拖放