【问题标题】:Cannot resize LinearLayout in height无法调整 LinearLayout 的高度
【发布时间】: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


【解决方案1】:

也许您为此视图设置了一些边距?尝试清除参数边距,LinearLayout 的height 应该是youScrollView.getMeasuredHeight()

【讨论】:

  • 你指的是哪个视图?我正在播放动画的那个?这是许多视图之一,我通过“在另一个视图下”向上翻译来隐藏它虽然感谢 .getMeasuredHeight() 的提示
  • 那个“视图”可能是 LinearLayout - margin 或 ScrollView - padding。你在表演什么动画?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-31
相关资源
最近更新 更多