本文实例为大家分享了android实现点击图片全屏展示的具体代码,供大家参考,具体内容如下
MainActivity:
public class MainActivity extends AppCompatActivity { private ImageView imageView; private Dialog dialog; private ImageView image; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); //小图的点击事件(弹出大图) imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.show(); } }); } private void init() { imageView = (ImageView) findViewById(R.id.image); //展示在dialog上面的大图 dialog = new Dialog(MainActivity.this,R.style.FullActivity); WindowManager.LayoutParams attributes = getWindow().getAttributes(); attributes.width = WindowManager.LayoutParams.MATCH_PARENT; attributes.height = WindowManager.LayoutParams.MATCH_PARENT; dialog.getWindow().setAttributes(attributes); image = getImageView(); dialog.setContentView(image); //大图的点击事件(点击让他消失) image.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); } }); } //动态的ImageView private ImageView getImageView(){ ImageView imageView = new ImageView(this); //宽高 imageView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); //imageView设置图片 @SuppressLint("ResourceType") InputStream is = getResources().openRawResource(R.drawable.lala); Drawable drawable = BitmapDrawable.createFromStream(is, null); imageView.setImageDrawable(drawable); return imageView; } }
布局文件:
style:
效果图:
没点击:
点击后:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。