我已经包含RecyclerView在里面NestedScrollView并设置
mRecyclerView.setNestedScrollingEnabled(false);
由于滚动RecyclerView设置为false,因此我将无法获得 的滚动位置,RecyclerView因此我将无法将分页放入RecyclerView.
我也试过这个
mRecylerview.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if(dy > 0) {
totalItemCount = linearLayoutManager.getItemCount();
lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
if (!isLoading && totalItemCount <= (lastVisibleItem + visibleThreshold)) {
// End has been reached
// Do something
if (mOnLoadMoreListener != null) {
mOnLoadMoreListener.onLoadMore();
isLoading = true;
}
}
} …Run Code Online (Sandbox Code Playgroud) pagination android android-recyclerview nestedscrollview android-nestedscrollview
我有一个应用程序,其中包含一个 Activity,多个 Fragments 模型,其中多个 Fragment 有一个 RecyclerView 来显示带有内容的卡片。我还实现了 Material Design 2.0 中的 BottomAppBar,一切都很好,除非 AppBar 阻止了 RecyclerView 中的最后一个 CardView。
在布局方面,我在一个 Fragment 内的 ConstraintLayout 中有一个 RecyclerView,它位于主要活动的 FrameLayout 中。
文档显示,要在 Scroll 上隐藏 BottomAppBar,我们需要在 NestedScrollView 中实现 RecyclerView。这里有一个关于 SO 的问题,其中的答案也说明了相同,但似乎没有实际的文档或示例来演示如何做到这一点,除了这篇关于 Medium 的文章,它在 Activity 中使用了 NestedScrollView直接,持有一个 CoordinatorLayout 持有一个 ConstraintLayout。
注意:我认为它也适用于魔法,因为在我的片段中复制布局在我的应用程序中根本没有任何影响。
我如何在这里使用 NestedScrollView?
PS:我需要有 TextView,因为我将 RecyclerView 设置为 VISIBILITY.GONE 并在没有数据可显示时将 TextView 设置为 VISIBLE。
片段布局
<android.support.constraint.ConstraintLayout 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:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="in.domain.APPNAME.Fragments.FragmentList">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewIncident"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="30dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" …Run Code Online (Sandbox Code Playgroud) android android-layout android-recyclerview android-nestedscrollview android-bottomappbar
我有一个recyclerView内幕nestedScrollView。我知道这是一个不好的做法,但有些情况我只能用这种方式处理。
<androidx.core.widget.NestedScrollView
android:id="@+id/nestedScroll"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="1"
tools:listitem="@layout/item_favorite_tournament"
tools:visibility="visible" />
</androidx.core.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
这是我的代码。我将向您展示滚动部分,我需要在其中获取firstVisibleItemPosition. 但它返回0。
private void initList(RecyclerView recycler, View labelNoResults) {
recycler.setAdapter(mAdapter);
recycler.setHasFixedSize(true);
mListLayoutManager = Objects.requireNonNull((LinearLayoutManager) recycler.getLayoutManager());
recycler.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
final int p = mListLayoutManager.findFirstVisibleItemPosition();
Log.d("Tag_1", "Position: " + p);
}
});
}
Run Code Online (Sandbox Code Playgroud)
我认为问题是因为nestedScrollView. 那么我怎样才能获得visibleItemPosition表单呢recyclerView?谢谢。
我正在尝试创建Android产品布局.页脚有两个按钮,它是固定按钮.当我滚动我的布局中附带的底部两个按钮时,你可以看到图像.请帮忙我该怎么办?
图片1
图2
滚动后
XML
<?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:id="@+id/coordinate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.chivazo.chivazoandroid.activities.SingleProductActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginBottom="30dp"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="@drawable/a"
app:layout_collapseMode="parallax" />
<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/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_single_product" />
<LinearLayout
android:id="@+id/groupbutton"
android:weightSum="2"
android:orientation="horizontal"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<android.support.v7.widget.AppCompatButton
android:layout_weight="1"
android:id="@+id/share"
android:text="share"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<android.support.v7.widget.AppCompatButton
android:layout_weight="1"
android:id="@+id/go_wishlist"
android:text="go to Wishlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) 我们有一个 NestedScrollView,它包含两个不同的RecyclerView垂直滚动。滚动布局位于SwipeRefreshLayout.
更新:我们知道getItemViewType(pos)方法并在其他地方使用它。但是这里我们有复杂的逻辑,将进一步分为 2 个不同的屏幕,因此我们为每个 RecyclerView 设置了两个单独的演示器,将它们合并为一个并在一个月内再次分离不是一种选择。
从某个时候,我们注意到使用滑动刷新更新屏幕开始冻结 UI:日志中的跳帧、无法使用 UI 进行任何操作、冻结进度条。最多需要五秒钟,但我们没有收到 ANR。它在开始时运行良好,在结束时冻结。如果我们notifyDataSetChanged()在适配器中移除,一切看起来都不错。
我们试图删除回收站视图之一,从ViewHolder.onCreate()和 中删除所有操作,onBindViewHolder()但没有帮助。此外,我们交叉检查了问题是否来自某些数据处理(我们使用 RxJava 2 来操作线程),我们看到所有与网络、数据库和数据处理相关的操作都是在非 UI 线程中进行的,并且目前已经完成当滞后开始时。
这是布局:
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height=«match_parent"
android:orientation="vertical"
>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content»
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation=«vertical"
android:paddingBottom="@dimen/spacing_bigger»>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycle_chats"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white_bg"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycle_friends"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white_bg"
/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud) android android-anr-dialog android-recyclerview android-nestedscrollview
这是真的吗?我想通过使用嵌套滚动视图在我的活动中滚动列表视图.请帮忙.提前致谢
<android.support.v4.widget.NestedScrollView
android:id="@+id/login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/insertkend_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listAksesoris">
</ListView>
</ScrollView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
我试图建立PreferenceFragment在CollapsingToolbarLayout.问题是元素太多PreferenceFragment而且没有显示.似乎NestedScrollView没有使用这些片段.这里的解决方案对我不起作用,因为我不能出于其他原因使用compat库.我该如何解决这个问题?
码:
<android.support.v4.widget.NestedScrollView
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:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_user_profile">
<FrameLayout
android:id="@+id/user_profile_content"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud) android preferencefragment android-collapsingtoolbarlayout android-nestedscrollview
我有一个RecyclerView内部NestedScrollView,我试图在滚动事件使用期间获取最后一个可见列表项的位置.以下代码允许我可靠地检测滚动事件:
val recyclerView = nestedScrollView.getChildAt(0) as RecyclerView
nestedScrollView.setOnScrollChangeListener { v: NestedScrollView?, scrollX: Int, scrollY: Int, oldScrollX: Int, oldScrollY: Int ->
val layoutManager = recyclerView?.layoutManager as? LinearLayoutManager
val lastVisiblePosition = layoutManager?.findLastVisibleItemPosition()
}
Run Code Online (Sandbox Code Playgroud)
然而问题是,这里lastVisiblePosition总是最终成为列表中的最后一项,无论这是否实际上是在scree上.我哪里可能出错?
android kotlin android-recyclerview android-nestedscrollview
我已经用底表实现了Google地图。但是,当我检查布局时,地图位于屏幕顶部,而不占据屏幕的整个宽度和高度。我已经尝试了多种方法来解决此问题,但是没有运气。
下面是布局代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android" >
<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:layout_weight="1">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_gravity="fill_vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:layout_gravity="fill_vertical"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.app.headcount.MapsActivity"
/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
<include layout="@layout/test"
android:id="@+id/design_bottom_sheet"/>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
您能否看一下这个问题,让我知道问题出在哪里?谢谢。
android android-layout android-fragments google-maps-android-api-2 android-nestedscrollview
我在“ Cordinator布局”中使用了“折叠工具栏”,但“折叠”栏仍然不会折叠,并且仍在滚动中。
这是activity_demo.xml-
<?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.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<!-- Fit the system windows for your CollapsingToolbarLayout
also set your height to wrap_content and give image a height-->
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="4dp"
app:expandedTitleMarginEnd="64dp">
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="244dp"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
android:src="@drawable/cheese"
app:layout_collapseMode="parallax"/>
<!-- Tell your toolbar to scroll|enterAlways -->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways"/>
<!-- add layout_gravity="bottom" -->
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:tabSelectedTextColor="?android:attr/textColorPrimaryInverse"
app:tabIndicatorColor="?android:attr/textColorPrimaryInverse"
app:tabIndicatorHeight="4dp"
android:layout_gravity="bottom"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout> …Run Code Online (Sandbox Code Playgroud) android android-collapsingtoolbarlayout android-nestedscrollview
android ×10
android-collapsingtoolbarlayout ×2
button ×1
java ×1
kotlin ×1
layout ×1
pagination ×1
scrollview ×1