【发布时间】:2014-12-14 19:22:46
【问题描述】:
我有一个包含一些 TextViews 和一个 ImageView 的屏幕,它位于具有垂直方向的 LinearLayout 中。我希望整个东西完全适合屏幕(无论它的大小是多少),其中 ImageView 是可以自我调整以适应这种情况的屏幕。
我在这里看到了这个问题的一些变体(包括this),但没有找到真正满足我要求的任何内容。
到目前为止,我使用了一个不是很“漂亮”的解决方案,即将整个 LinearLayout 放在一个 ScrollView 中,并使用自定义 ImageView 在其 onMeasure 方法上计算两者之间的增量ScrollView 的高度到屏幕的高度。如果前者大于后者,则从 ImageView 的测量高度中减去 delta。
这个解决方案并不完美,我真的很想知道是否有更好的解决方案。我确定有。
感谢您的帮助。
编辑:这是布局xml
<com.xxx.widgets.LockableScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:custom="http://schemas.android.com/apk/res/com.venews"
android:layout_width="match_parent"
android:layout_height="match_parent"
custom:scrollable="false"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/login_horizontal_margin"
android:paddingRight="@dimen/login_horizontal_margin"
android:orientation="vertical">
<com.xxx.widgets.ResizableToFitScreenImageView android:id="@+id/login_logo_image"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/login_logo_margin"
android:layout_marginBottom="@dimen/login_logo_margin"
android:src="@drawable/ic_logo_and_name"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/login_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"/>
<TextView android:id="@+id/login_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/login_username"/>
(...Other stuff...)
</RelativeLayout>
</LinearLayout>
</com.xxx.widgets.LockableScrollView>
EDIT2:这是一个我希望能让事情更清楚的草图。
草图显示了 2 种不同的屏幕尺寸,因为此解决方案还需要支持具有不同屏幕尺寸的不同设备。
【问题讨论】:
-
你能发布你的xml吗?
-
很难理解您想要实现的目标,能否请您发布您想要的 UI 草图?
-
@warl0ck08 编辑了我的问题。
-
@Egor 编辑了我的问题 2
-
图像视图上的 adjustViewImageBounds = true 没有为您调整大小的任何特殊原因?