android实现点击图片全屏展示效果
作者:Sweety_ykx 时间:2023-12-06 22:42:25
本文实例为大家分享了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>
效果图:
没点击:
点击后:
来源:https://blog.csdn.net/ykx_1448488568/article/details/86238620
标签:android,图片全屏
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java中用enum结合testng实现数据驱动的方法示例
2021-08-04 07:44:21
![](https://img.aspxhome.com/file/2023/9/65179_0s.png)
Android AlertDialog(对话框)实例详解
2023-07-19 11:37:55
![](https://img.aspxhome.com/file/2023/6/126776_0s.jpg)
MyBatis-Plus代码生成器的使用详解
2022-09-04 23:14:40
![](https://img.aspxhome.com/file/2023/4/85824_0s.png)
合成聚合复用原则_动力节点Java学院整理
2023-06-27 22:05:20
![](https://img.aspxhome.com/file/2023/9/57599_0s.png)
C#事件标准命名规则及说明(包括用作事件类型的委托命名)
2022-02-27 06:57:43
java基础之泛型知识点总结
2021-09-03 21:30:29
Java多线程事务回滚@Transactional失效处理方案
2021-06-20 19:19:28
![](https://img.aspxhome.com/file/2023/2/82312_0s.png)
Python调用Java可执行jar包问题
2021-06-02 10:26:26
![](https://img.aspxhome.com/file/2023/9/102899_0s.png)
Android 应用中插入广告详解及简单实例
2022-11-22 20:40:04
android Gallery组件实现的iPhone图片滑动效果实例
2022-09-27 06:38:17
![](https://img.aspxhome.com/file/2023/6/99786_0s.jpg)
springboot 多数据源的实现(最简单的整合方式)
2022-08-20 02:30:11
java日期格式化SimpleDateFormat的使用详解
2023-08-25 03:22:15
![](https://img.aspxhome.com/file/2023/0/58460_0s.png)
c# 快速排序算法
2021-10-18 07:33:20
![](https://img.aspxhome.com/file/2023/6/84476_0s.png)
MyBatis中的properties配置(推荐)
2023-06-04 20:47:58
JAVA8 十大新特性详解
2023-07-02 10:03:27
Java从服务端下载Excel模板文件的两种方法
2021-08-29 05:44:40
![](https://img.aspxhome.com/file/2023/5/67115_0s.jpg)
解决Maven项目中 Invalid bound statement 无效的绑定问题
2021-08-13 10:30:41
![](https://img.aspxhome.com/file/2023/3/99883_0s.png)
Java设计模式之工厂模式
2023-12-18 01:40:50
![](https://img.aspxhome.com/file/2023/9/60339_0s.png)
Android入门教程之ListView的具体使用详解
2022-02-12 06:35:59
![](https://img.aspxhome.com/file/2023/5/122235_0s.jpg)
WMI获取硬件信息封装函数方法(联想台式机出厂编号 CPUID BIOS序列号 硬盘信息 显卡信息 MAC地址)
2023-10-03 13:39:54