亲宝软件园·资讯

展开

android点击图片全屏展示 android实现点击图片全屏展示效果

Sweety_ykx 人气:0
想了解android实现点击图片全屏展示效果的相关内容吗,Sweety_ykx在本文为您仔细讲解android点击图片全屏展示的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:android点击图片全屏展示,android点击图片全屏,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;
 }
}

布局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context=".MainActivity">
 
 <ImageView
 android:id="@+id/image"
 android:src="@drawable/lala"
 android:layout_centerInParent="true"
 android:layout_width="200dp"
 android:layout_height="200dp" />
 
</LinearLayout>

style:

<style name="FullActivity" parent="AppTheme">
 <item name="windowNoTitle">true</item>
 <item name="android:windowFullscreen">true</item>
</style>

效果图:

没点击:

点击后:

加载全部内容

相关教程
猜你喜欢
用户评论