【发布时间】:2016-11-29 01:36:43
【问题描述】:
我的 ScrollView 遇到了这个令人沮丧的问题,这是我的层次结构:
ScrollView (Vertical)
LinearLayout (Vertical)
ImageView weight= 0.5
Whatever weight= 0.1
Whatever weight= 0.2
Whatever weight= 0.2
如果我删除 ScrollView(并让 LinearLayout 作为主要项目),这适用于任何 Image :图像占据屏幕大小的 50%,而其他视图占据其余部分。
但是,当 ScrollView 在这里时,如果我的图像太高,“权重”参数将被完全忽略:图像会尽其所能适应屏幕宽度,然后显然太高并且需要超过屏幕的 50%。编辑:实际上,所有“重量”属性似乎都被忽略了:
我希望线性布局完全适合而无需滚动。那可能吗 ?我尝试更改一些图像选项(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,因为我使用的是 PullToRefresh ScrollView
【问题讨论】:
-
只是出于好奇,如果你不想滚动,为什么需要滚动视图?
-
基本上这个^。滚动视图没有维度,它可以是无限的。 50% 你期望你的 imageview 是什么?如果是线性布局,它知道。 ScrollView 根据需要占用尽可能多的空间。
-
这似乎不对。看看developer.android.com/reference/android/support/percent/…这可能是你需要的。
-
如果你想修复它,在 ScrollView 中对布局进行分组是没有意义的。
-
我需要这个 ScrollView,因为我正在使用 PullToRefresh 库和 ScrollView。当用户尚未滚动时,我希望我的图像为屏幕大小的 50%。
标签: java android xml scrollview android-linearlayout