在android中将一张图像放在另一张图像上

发布于 2024-11-16 01:42:51 字数 424 浏览 4 评论 0原文

我在 android 中有一个用户点击的 imageButton 。然后在他点击后,我希望在其顶部显示一个勾号或十字图像。 怎么可能呢?

            <ImageButton android:layout_width="wrap_content"
            android:text="Button" android:id="@+id/button1"
            android:layout_height="wrap_content" android:layout_gravity="center_horizontal"
            android:background="@drawable/rhino" android:layout_marginRight="20dp"></ImageButton>

I have a imageButton in android which user clicks. Then after his click I want t0 show a tick or a cross image on the toip of it.
How is it possible?

            <ImageButton android:layout_width="wrap_content"
            android:text="Button" android:id="@+id/button1"
            android:layout_height="wrap_content" android:layout_gravity="center_horizontal"
            android:background="@drawable/rhino" android:layout_marginRight="20dp"></ImageButton>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

紙鸢 2024-11-23 01:42:51

将 ImageButton 和刻度图像放入 FrameLayout 中,并使刻度图像的可见性“Invisible”。因此,当您单击 ImageButton 时,请将 Tick Image 的状态更改为 Visible。

put your ImageButton and the tick image in a FrameLayout and make the visbility of the Tick image "Invisible" . So when you click on the ImageButton then change the state of Tick Image to Visible.

污味仙女 2024-11-23 01:42:51

获取对 ImageButton 的引用,然后使用其 setImage 方法之一,例如 setImageResource

Get a reference to your ImageButton and then use one of its setImage methods, such as setImageResource.

倾城月光淡如水﹏ 2024-11-23 01:42:51

您可以使用 ImageView 实现相同的效果。使用 ImageView

testimage = (ImageView) findViewById(R.id.imageview);



testimage.setOnClickListener(listener);

编写逻辑,在 onclick 事件中将两种类型的图像设置为 imageview

public OnClickListener listener=new OnClickListener(){
        @Override
        public void onClick(View arg0) {
            System.out.println("..set image button..");

            Drawable[] layers = new Drawable[2];
            layers[0] = getResources().getDrawable(R.drawable.btn_call);
            layers[1] = getResources().getDrawable(R.drawable.blue_unfocus);
            System.out.println(layers[1]+"...Drawable..."+layers[0]);
            LayerDrawable layerDrawable = new LayerDrawable(layers);
            testimage.setImageDrawable(layerDrawable);

        }
    };

谢谢
迪帕克

You can achieve the same using ImageView. Use ImageView

testimage = (ImageView) findViewById(R.id.imageview);



testimage.setOnClickListener(listener);

write the logic to set both type of image to imageview in onclick event

public OnClickListener listener=new OnClickListener(){
        @Override
        public void onClick(View arg0) {
            System.out.println("..set image button..");

            Drawable[] layers = new Drawable[2];
            layers[0] = getResources().getDrawable(R.drawable.btn_call);
            layers[1] = getResources().getDrawable(R.drawable.blue_unfocus);
            System.out.println(layers[1]+"...Drawable..."+layers[0]);
            LayerDrawable layerDrawable = new LayerDrawable(layers);
            testimage.setImageDrawable(layerDrawable);

        }
    };

Thanks
Deepak

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文