【发布时间】:2017-09-09 02:47:34
【问题描述】:
我有一个带有 SwipeRefreshLayout 的片段,将在运行时添加到 Activity 的 FrameLayout 中。
问题在于 SwipeRefreshLayout 的高度始终为 0,无论 height 参数值是什么(wrap_content 或 match_parent)。
这是我的片段代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/expensesLL"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/expenses_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingBottom="@dimen/recycler_view_padding_bottom"
android:paddingTop="@dimen/list_item_margin" />
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
这是我的活动代码:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layoutDirection="ltr"
tools:context=".expenses.ExpensesActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/dr_nav_header"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleGravity="center_horizontal|bottom"
app:expandedTitleMarginBottom="@dimen/title_margin_bottom"
app:expandedTitleTextAppearance="@style/ExpandedTitle"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<FrameLayout //Inside this frame my fragment will be added
android:id="@+id/contentFrame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_add_expense"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/controllers_padding"
android:src="@drawable/ic_add"
app:fabSize="normal"
app:layout_anchor="@id/app_bar_layout"
app:layout_anchorGravity="bottom|end" />
</android.support.design.widget.CoordinatorLayout>
有什么建议吗?
【问题讨论】:
-
“SwipeRefreshLayout 高度始终为 0” - 你是如何确定的,确切地说?
-
当我将高度固定为 200 dp(例如)时,它将显示出来!
-
可能是与你那里的无关
ViewGroups“战斗”。你不需要NestedScrollView围绕FrameLayout,因为RecyclerViews 会自行滚动,而RecyclerView周围的LinearLayout并不是必需的,除非你在那里放了其他东西. -
问题是如果我删除了 NestedScrollView 那么 Framelayout 将流过 AppBarLayout 并且不会被附加在它之后。知道我正在实现一个可折叠的工具栏。我也尝试删除 LinearLayout 但没有成功。
-
感谢 Mike M. 的“战斗”提示
标签: android android-recyclerview android-framelayout swiperefreshlayout