我正在使用ScrollView时遇到了麻烦,以下是我的层级结构:
注意:我需要使用ScrollView,因为我正在使用下拉刷新ScrollView。
ScrollView (Vertical)
LinearLayout (Vertical)
ImageView weight= 0.5
Whatever weight= 0.1
Whatever weight= 0.2
Whatever weight= 0.2
如果我移除ScrollView(让LinearLayout作为主要项),这将正常工作并适用于任何图像:该图像占据屏幕大小的50%,其他视图填满剩余空间。
然而,当ScrollView存在时,如果我的图片太高,“weight”参数将完全被忽略:图像会尽其所能适应屏幕宽度,然后显然会过高并且占据超过屏幕的50%。编辑:实际上,所有“weight”属性似乎都被忽略了:
我希望LinearLayout完美适合,无需滚动。 是否可能? 我已经尝试更改某些图像选项(scaleType,adjustViewBounds),但我没有成功。
以下是整个xml代码:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:adjustViewBounds="true"
android:src="@drawable/testing" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:text="I'M A TEST" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:text="I'M A TEST" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:text="I'M A TEST" />
</LinearLayout>
</ScrollView>
注意:我需要使用ScrollView,因为我正在使用下拉刷新ScrollView。