【发布时间】:2018-10-12 18:10:23
【问题描述】:
我有一个 RelativeLayout 和一个名为 ZoomieView 的自定义 ImageView,它允许我捏合缩放图像。我想让图像增长到整个屏幕的大小,所以我将ZoomieView 的宽度和高度设置为match_parent。现在我还想向 RelativeLayout 添加页眉和页脚,这样ZoomieView 就位于页眉和页脚之间,如下所示:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBgBlackTintDarkest"
android:id="@+id/full_displayer_master_container"
android:orientation="vertical">
<!-- Submission header -->
<LinearLayout
android:id="@+id/big_display_title_container"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:orientation="vertical">
</LinearLayout>
<!-- Image zoom view-->
<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"/>
<!-- footer -->
<LinearLayout
android:id="@+id/full_display_snack_bar_container"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="@drawable/snack_bar_selector"
android:clickable="true"
android:orientation="horizontal">
</LinearLayout>
</RelativeLayout>
如果我有一个小图像,这可以正常工作,因为图像足够小以至于它不会覆盖页眉/页脚,但是当我尝试加载大图像时,由于我的高度/宽度,页眉和页脚会被覆盖是 match_parent。
我需要保持 match_parent 的高度/宽度,但我也不希望在加载视图时覆盖页眉/页脚(如果稍后在用户放大图片时覆盖页眉/页脚,这很好,不过)。
有没有一种方法可以调整我的图像大小,以便在视图加载时ZoomieView 在我的页眉和页脚之间居中,但在我放大图像时允许ZoomieView 覆盖页眉/页脚?
将android:layout_below="header" android:layout_above="footer" 添加到我的ZoomieView 将不起作用,因为它不允许ZoomieView 在放大时扩大整个屏幕尺寸。
这就是我现在所拥有的(糟糕):
【问题讨论】:
-
为什么你没有使用线性布局而不是相对布局。在这种情况下会很容易。
-
我相信我确实尝试过使用 LinearLayout。愿意解释一下你的意思吗?
-
你提前知道页眉/页脚的大小吗?还是在运行时是动态的?
-
它在运行时是动态的
标签: android android-layout android-imageview android-view