我是靠谱客的博主 整齐大象,这篇文章主要介绍android实现点击图片全屏展示效果,现在分享给大家,希望可以做个参考。

本文实例为大家分享了android实现点击图片全屏展示的具体代码,供大家参考,具体内容如下

MainActivity:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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; } }

布局文件:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<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:

复制代码
1
2
3
4
<style name="FullActivity" parent="AppTheme"> <item name="windowNoTitle">true</item> <item name="android:windowFullscreen">true</item> </style>

效果图:

没点击:

点击后:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持靠谱客。

最后

以上就是整齐大象最近收集整理的关于android实现点击图片全屏展示效果的全部内容,更多相关android实现点击图片全屏展示效果内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(641)

评论列表共有 0 条评论

立即
投稿
返回
顶部