【发布时间】:2018-09-27 14:21:21
【问题描述】:
我有一个ImageView 夹在两个LinearLayout 之间。 ImageView 具有缩放功能,允许我放大和缩小图像 - 这意味着图像可以放大到屏幕的整个大小(match_parent)。
如果我加载一个非常高(高度)的图像,图像会与两个 LinearLayout 重叠,这在 到达 屏幕时是不行的,但如果用户决定稍后放大则可以。有没有办法在初始化时“限制” ImageView 的高度,但也允许它增大整个屏幕尺寸?
以下是一个“高”图像被错误加载的示例,因为它覆盖了顶部的LinearLayout 文本:
这就是我希望加载图像的方式,并且能够增长到前一个图像的大小:
这是我的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBgBlackTintDarker"
android:orientation="vertical"
android:paddingTop="20dp">
<!-- Title at the top -->
<LinearLayout
android:id="@+id/big_display_title_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical">
<!-- Title stuff here-->
</LinearLayout>
<!-- Middle custom ImageView with ability to zoom-->
<com.sometimestwo.moxie.ZoomieView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/full_displayer_image_zoomie_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"/>
<!-- Bottom toolbar-->
<LinearLayout
android:id="@+id/big_display_snack_bar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/transparent"
android:orientation="horizontal">
<!-- Bottom toolbar stuff-->
</LinearLayout>
</RelativeLayout>
编辑:这是一个 GIF 来说明我的经历:
图像可以根据需要放大和缩小,但我需要在初始化时将图像放在标题和底部工具栏之间,这样它就不会覆盖任何东西(直到用户决定放大)。
【问题讨论】:
-
您接受使用 ConstrainLayout 的解决方案吗?
-
当然。我在 ConstraintLayout 方面做得不多,但我愿意学习。
-
你能分享你的项目吗?
-
我认为它太大而无法浏览...但是我已经在我的帖子中添加了一个 GIF 来说明我在寻找什么
-
您是否提前知道您的顶部和底部线性布局有多大?或者它们的大小可以动态变化吗?
标签: android android-layout android-imageview android-relativelayout