【问题标题】:FrameLayout does not match the height of NestedScrollViewFrameLayout 与 NestedScrollView 的高度不匹配
【发布时间】:2016-03-01 22:42:54
【问题描述】:

我在 NestedScrollView 中有一个 FrameLayout,如

<android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#000000">

但是 FrameLayout 没有填满 NestedScrollView 的高度。我该如何解决这个问题?

【问题讨论】:

  • 我认为在框架布局中设置重力 = 中心或其他
  • 执行android:layout_gravity="center"android:layout_gravity="center|fill_vertical" 似乎不起作用
  • android:fillViewport="true"check this 添加到android.support.v4.widget.NestedScrollView

标签: android android-layout android-framelayout nestedscrollview


【解决方案1】:

检查此解决方案
使用fillViewport="true" 如果需要,此属性会使滚动视图的子视图扩展到 ScrollView 的高度。当child高于ScrollView时,该属性无效。

 <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
      android:fillViewport="true"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

【讨论】:

  • 我已经尝试过android:fillViewport="true"。但是当我这样做时,我在setContentView(R.layout.activity_main); 行得到了一个 nullPointerException
  • 好的,我知道了,我认为你应该在线性布局中使用整个android.support.v4.widget.NestedScrollView
  • 似乎是其他原因导致了崩溃。所以谢谢(虽然我已经尝试过fillViewport)。我清理了项目,现在它正在运行,但我不知道它为什么会失败。
  • 这就像 android.support.v4.widget.NestedScrollView 的魅力
  • 这正是我想要的,非常感谢!
猜你喜欢
  • 2017-05-25
  • 2012-08-18
  • 1970-01-01
  • 2021-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-03
  • 2011-08-09
相关资源
最近更新 更多