【问题标题】:Dynamic content inside scrollview lost last view滚动视图中的动态内容丢失了最后一个视图
【发布时间】:2015-06-18 14:08:45
【问题描述】:

我有带有 LinearLayout 和按钮的 ScrollView:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:id="@+id/layout_scroll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/layout_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:background="@color/card_color"
            android:orientation="vertical"
            android:padding="10dp">

        </LinearLayout>

        <Button
            android:id="@+id/button_leave"

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:text="@string/leave" />

    </LinearLayout>
</ScrollView>

然后在代码中我将视图添加到layout_list:

View view = LayoutInflater.from(this)
        .inflate(R.layout.item_member, mLayoutMemberList, true);

如果我添加的项目不多,那么button_leave 是可见的。但是,如果我添加了很多项目(比屏幕上显示的更多),那么即使我向下滚动,屏幕上也不会显示按钮。

更新:

看起来是android.support.design.widget.CoordinatorLayout 的错误。我将其更改为简单的线性布局,一切正常。

【问题讨论】:

  • 你能尝试改变父LinearLayout的高度来匹配父,目前它是换行的。 'android:layout_height="wrap_content"'
  • 不幸的是它没有帮助,它提供 lint 警告:应该使用 wrap_content。

标签: android scrollview android-linearlayout


【解决方案1】:

试试这样:

我认为布局视图工作正常并尝试以下代码,

 LayoutInflater inflater = context.getLayoutInflater();
 View rowView=inflater.inflate(R.layout.layout_list, null, true);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-09
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多