【发布时间】:2016-09-24 03:01:00
【问题描述】:
我在Scrollview 中有一个LinearLayout。做了一些动画后,当我向下滚动时,底部有空白区域。所以我想用这段代码调整LinearLayout的大小
ViewGroup.LayoutParams params = _linearLayoutMainWrapper.getLayoutParams();
params.height = 100;
_linearLayoutMainWrapper.setLayoutParams(params);
但它不起作用,只是没有发生任何事情。当我尝试调整 width 的大小时,它正在工作。
XML 是
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:fillViewport="true"
android:id="@+id/scrollViewMain">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical"
android:paddingLeft="16dip"
android:paddingRight="16dip"
android:id="@+id/linearLayoutMainWrapper">
<!-- a lot of stuff -->
</LinearLayout>
</ScrollView>
【问题讨论】:
-
你能展示你的“_linearLayoutMainWrapper”xml布局吗?有时错误在于属性,例如在某些情况下,将高度设置为 wrap_content 会阻止您以后更改高度。
-
为什么不在 LinearLayout 上使用 android:layout_height="wrap_content"?您的布局总是从滚动视图中获取高度。也许尝试编辑滚动视图的高度或将线性布局高度属性更改为 wrap_content。
-
我做了,它没有用,所以我改变了它,因为上面的评论说“wrap_content”会导致问题。不过还是不行。
-
给布局高度一些恒定值并再次检查。它可能会有所帮助,因为该值不会依赖于任何其他元素。
标签: android android-layout android-linearlayout layoutparams