我想要隐藏图像,然后在10-20秒后使其可见。
这是我的代码:
public class MainActivity extends Activity implements OnClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imgv1 = (ImageView) findViewById(R.id.cool);
imgv1.setOnClickListener(this);
// This is the image which I want to first hide and then show it after few seconds
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public void onClick(View v) {
Intent startactivity = new Intent(this,signin.class);
startActivity(startactivity);
}
}
答案 0 :(得分:3)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView imgv1 = (ImageView) findViewById(R.id.cool);
imgv1.setVisibility(View.INVISIBLE);
new Handler().postDelayed(new Runnable(){
public void run() {
imgv1.setVisibility(View.VISIBLE);
}
}, timeInMillis);
imgv1.setOnClickListener(this);
}
timeInMillis
是您要等到ImageView
之前要等待的时间。
答案 1 :(得分:0)
onCreate()
中的
imgv1.setVisibility(View.GONE);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
imgv1.setVisibility(View.VISIBLE);
}
},10 * 1000); // For 10 seconds