android - 单击时使 ImageView 全屏
问题描述
我有两个图像的视图
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/top_section"
android:orientation="vertical"
android:layout_marginTop="120dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="170dp"
android:id="@+id/top_image"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/top_text"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bottom_section"
android:orientation="vertical"
android:layout_alignParentBottom="true">
<ImageView
android:layout_width="match_parent"
android:layout_height="170dp"
android:id="@+id/bottom_image"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bottom_text"/>
</LinearLayout>
我想这样做,如果用户单击图像视图,它会变成全屏并正确旋转以占据全屏。
到目前为止,我已经尝试过(例如,如果单击顶部)
topText.setVisibility(View.GONE)
bottomSection.setVisibility(View.GONE)
getSupportActionBar().hide();
getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
但图像并不是真正的全屏。我将如何使图像全屏显示?我一直在考虑可能有三分之一的图像视图,并使其与宽度和高度的父级匹配,并使其在点击时可见。
解决方案
创建另一个名为 的活动ImageZoomedActivity
,通过意图(可能是 url、本地文件位置等)和OnCreate
方法将图像数据传递给它:
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.popup_photo_full);
supportPostponeEnterTransition();
if(getIntent().hasExtra("file")) {
imageFile = new File(getIntent().getStringExtra("file"));
GlideApp.with(this).asBitmap()
.load(imageFile)
.into(image);
supportStartPostponedEnterTransition();
}
上面的代码适用于通过意图传递的本地文件 URI。
这两行
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
让您全屏进行活动。也可以在带有缩略图的第一个活动和带有全屏图像的第二个活动之间进行转换。如果您想了解更多信息,请给我发邮件,我可以将详细代码发送给您。
推荐阅读
- google-cloud-platform - Google Data Studio 如何按位置替换字符串字符?
- java - 无法使用 WebCrypto 验证 ECDSA 签名
- pytorch - 有没有办法从cad模型中提取几何信息进行特征识别?
- postgresql - postgresql中的oracle时间戳等效数据类型
- macos - localhost:3000 在遵循 Docker 网站上的教程时不起作用
- html - iFrame 在某些视口上闪烁
- python - 如何使用套接字连接到另一台计算机?
- c# - 如何使用linq c#优化嵌套循环并从另一个列表中过滤
- javascript - 我的 fabric.js sclaing 方法在对象旋转后不起作用
- unity3d - 如何在unity3d中在位置实例化预制件(2D游戏)