【问题标题】:Make ImageView fullscreen on click单击时使 ImageView 全屏
【发布时间】:2019-01-21 16:35:27
【问题描述】:

我有两个图像的视图

<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);

但图像并不是真正的全屏。我将如何使图像全屏显示?我一直在考虑可能有三分之一的图像视图,并使其与宽度和高度的父级匹配,并使其在点击时可见。

【问题讨论】:

  • 您将图像高度设为 170dp。将 match_parent 设为 top_image

标签: android android-layout imageview android-imageview fullscreen


【解决方案1】:

创建另一个名为ImageZoomedActivity 的活动,通过intent(可以是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);

让您全屏制作活动。 也可以在带有缩略图的第一个活动和带有全屏图像的第二个活动之间进行转换。如果您想了解更多信息,请私信我,我可以将详细代码发送给您。

【讨论】:

  • 由于 SO 不支持用户或网络之间的通信,因此无法真正 pm 你。有没有机会发布到 github 的链接之类的?
  • 我会在 pastebin 上发帖,不过我不确定我今天能不能做到!明天我一定会做到的?
  • @Quillion 活动 A 代码:pastebin.com/TvrXwCnc 活动 B(详细)代码:pastebin.com/RSPLUe8F 要使转换正常工作,请查看:medium.com/@andkulikov/…
猜你喜欢
  • 2016-03-17
  • 2015-02-01
  • 1970-01-01
  • 2014-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多