如何创建带有叠加图像的 ImageButton?
我有一个按钮,最初作为占位符,但是一旦用户进行身份验证,它就会更改为该用户的自定义图像。
<ImageButton android:id="@+id/button"
android:background="@null"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/button_default"/>
后来:
ImageButton ib = (ImageButton)findViewById(R.id.button);
ib.setImageBitmap(previouslyDecodedBitmap);
但这看起来很糟糕。我不知道如何正确设置它的样式,以便新解码的位图具有正确的大小并且行为类似于 ImageButton
。我怀疑除了 ImageButton
之外,我还可以使用一些小部件组合来实现此目的?我希望通过将 ImageView
作为子项添加到 ImageButton
中,将 ImageView
嵌套在 ImageButton
之上,但这似乎并非如此被允许(在 Silverlight 中......)。
无论如何,欢迎任何有关如何正确执行此操作的建议。谢谢。
I have a button that starts out as a placeholder, but once the user authenticates, it changes to a custom image for that user.
<ImageButton android:id="@+id/button"
android:background="@null"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/button_default"/>
And then later:
ImageButton ib = (ImageButton)findViewById(R.id.button);
ib.setImageBitmap(previouslyDecodedBitmap);
But this looks terrible. I can't figure out how to style it properly so that the newly decoded bitmap is the right size and behaves like an ImageButton
. I suspect there is some combination of widgets I can use other than ImageButton
to achieve this? I was hoping I could just nest an ImageView
on top of the ImageButton
by adding it as a child to ImageButton
, but that doesn't seem to be allowed (it is in Silverlight...).
Anyway, any suggestions on how to properly do this are welcome. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是使用框架布局并将按钮和图像一个放在另一个之上,顶部是 imageview ,保持其不可见(android:visibility = "invisible")
单击按钮并进行身份验证后,使其在按钮上可见,否则您甚至可以隐藏下面的按钮并仅在顶部显示图像。
One way would be to use frame layout and place buttons and image one over the other , top being imageview , keep it invisible (android:visibility = "invisible")
On clicking the button and authenticating , make it visible over the button or else even you can hide the button below and show only image on top.