Change ImageView

I installed ImageView in main.xml if I want to access it from my View class and make it visible = false, how can I do this programmatically?

thanks

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); theView = new GameView(this); theView.setBackgroundResource(R.layout.main); setContentView(theView); 
+7
source share
5 answers

For example, in your XML layout file, there is imageview1

 <ImageView android:id="@+id/imageview1" android:layout_gravity="center" android:layout_width="fill_parent" android:layout_height="fill_parent" /> 

in your java src,

 ImageView img=(ImageView)findViewById(R.id.imageview1); img.setVisibility(View.GONE); img.setVisibility(View.VISIBLE); img.setVisibility(View.INVISIBLE); 

you can google the difference between View.Gone and View.VISIBLE

+9
source

First you should get a link to this view object. What sets the visibility property of this object to View.INVISIBLE

 ImageView imageView = (ImageView)findViewById(R.id.image_view); imageView.setVisibility(View.INVISIBLE); 
+1
source

Use this property in the xml of this Imageview

 android:visibility="visible" 

and programmatically change the visibility on this particular event:

 image.setVisibility(ImageView.GONE) 

where the image is an instance of this image obtained through findViewById ()

+1
source
 ImageView myView = (ImageView) findViewById(R.id.myView); myView.setVisibility (android.View.INVISIBLE); 

http://developer.android.com/reference/android/view/View.html#INVISIBLE

http://developer.android.com/reference/android/view/View.html#findViewById%28int%29

+1
source

Suppose you have an ImageView called ImageView .

Now enter ImageView as

 imageView=(ImageView) findViewById(R.id.your_image_view); 

Now that you are trying to hide ImageView , just use imageView.setVisibility(View.INVISIBLE);

Hope this helps you

+1
source

All Articles