我可以隐藏的布局,(尺寸和背景)的图像按钮,直到调用设置可见? [英] Can I hide an image button on a layout, (dimensions and background) until a call to set visible?

查看:99
本文介绍了我可以隐藏的布局,(尺寸和背景)的图像按钮,直到调用设置可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的布局XMLS一个隐藏的图像按钮,与背景设定为一个绘制的图像。我设置了知名度看不见,因为我只希望图像在一段时间一次显示每一个。问题是,即使绘制没有显示,图像按钮仍然需要我们的空间 - 有没有一种方法来隐藏背景图像,并使它的尺寸0,直到我要求它在我的主类显示<? / P>

谢谢!

编辑:所以在我的XML,如何将我写

 &LT; ImageButton的机器人:ID =@ + ID / MYIMAGE机器人:知名度=隐形
机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =中心的Andr​​oid版本:后台=@可绘制/ my_image&GT;&LT; / ImageButton的&GT;
 

我想有形象永远消失了,除非在一定条件下发生,那么我想要的形象,一个条件是可见的。所以在我的xml,我需要被设置为走了,但在我的条件语句,所以我说是这样的:

myimage.setVisibility(SHOW);

解决方案

所有的观点,包括ImageButton的,从android.view.View继承,所以他们都可以设置一个可见性属性。而不是设置绘制资源的知名度,对ImageButton的设置。

I have a hidden image button in one of my xmls layouts, with a background set to a drawable image. I set the visibility to invisible, as I only want the image to display every once in a while. The problem is, even if the drawable isn't shown, the image button still takes us space - Is there a way to hide the background image, and make it's dimensions 0 until I call on it to be shown in my main class?

Thanks!

Edit: So in my xml, how would I write that?

<ImageButton android:id="@+id/myimage" android:visibility="invisible" 
android:layout_width="wrap_content" android:layout_height="wrap_content" 
android:layout_gravity="center" android:background="@drawable/my_image"></ImageButton>

I want to have the image always gone, unless a certain condition occurs, I then want the image to be visible under that one condition. So in my xml I would need to be set to GONE, but in my conditional statement so I say something like:

myimage.setVisibility(SHOW);?

解决方案

All views, including ImageButton, inherit from android.view.View, so they all have a visibility attribute that can be set. Instead of setting the visibility of the drawable resource, set it on the ImageButton.

这篇关于我可以隐藏的布局,(尺寸和背景)的图像按钮,直到调用设置可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆