android – 更改ImageView

前端之家收集整理的这篇文章主要介绍了android – 更改ImageView前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在main.xml中设置了一个 ImageView,如果我想从我的View类访问它并使其可见= false,我该如何以编程方式执行此操作?

谢谢

  1. public void onCreate(Bundle savedInstanceState) {
  2. super.onCreate(savedInstanceState);
  3. theView = new GameView(this);
  4. theView.setBackgroundResource(R.layout.main);
  5. setContentView(theView);

解决方法

例如,在布局xml文件中,有一个imageview1
  1. <ImageView
  2. android:id="@+id/imageview1"
  3. android:layout_gravity="center"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. />

在你的java src中,

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

你可以谷歌View.Gone和View.VISIBLE之间的区别

猜你在找的Android相关文章