我有内置WebView的NestedScrollView,我正在使用折叠工具栏.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
>
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
当我加载webView的内容并且内容比屏幕更高时,它的效果很好.工具栏在滚动时隐藏/显示.
第二种情况是webview的内容很小.当我挂NestedScrollView在底部并向上拖动时,工具栏隐藏并拖动到显示的底部工具栏.
当我尝试拖动WebView它不起作用时,视图仍然在同一个地方.
知道如何解决这个问题.
当内容WebView太小或禁用滚动时,不允许隐藏工具栏WebView
我在我的片段中使用Coordinator布局以及NestedScrollView来折叠工具栏动画。我正在将视图动态添加到嵌套的Scrollview容器中。我已经在NestedScrollView内的视图上实现了onClickListener,但是对任何视图的第一次单击始终会被忽略。当我第二次点击或超过其正常工作时。我的XML的代码如下:
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2015 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR …Run Code Online (Sandbox Code Playgroud) android android-support-library android-support-design nestedscrollview
我使用的内部回收其放在嵌套的滚动视图内的多个视图的持有人,有一个在自然行为的改变onBindViewHolder() ,因为嵌套滚动,回收器视图getItemViewType()所有项目被称为内onBindViewHolder()发起回收适配器时,例如,我有20个项目意味着在正常情况下只有三个项目在启动时调用,但是在嵌套滚动视图的情况下,所有20个视图在第一次加载时创建.
Xml文件
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/light_gray_vd">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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"
app:contentScrim="@color/primaryColor"
app:expandedTitleMarginEnd="16dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax">
<include
android:id="@+id/inc_gallery"
layout="@layout/proj_galery_new"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</FrameLayout>
<View
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar1"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="top"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<include
android:id="@+id/toolbar_header_view"
layout="@layout/header_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/vde_mv_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<FrameLayout
android:id="@+id/rlCollapseScroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/view_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</FrameLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) 我在StackOverflow上看了几个类似的事件.但似乎没有一个适用于我的情况.我遇到的问题是我的RecyclerView正在运行,但没有显示任何内容.我已经运行了多个测试来试图弄清楚它为什么不起作用,但所有人都支持它正常工作的事实.
登录getItemCount返回3,这是正确的数字.我只是不明白为什么它没有显示.我回顾了我在之前的活动中所做的回收站视图,它们都匹配到一定程度(其他回收商有更多信息可以设置).
感谢您提供任何帮助.
编辑:我发现了这个问题,但仍然需要帮助.正是崩溃的工具栏导致了它.如果我在NestedScrollView外移动RecyclerView,我可以看到这些项目.但是,内容不能像activity_project_detail.xml中注释掉的TextView那样正确移动.我想我的新问题是如何在NestedScrollView中使用RecyclerView.谢谢!
ProjectDetailsActivity.java
package com.austinerck.projectpanda.activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import com.austinerck.projectpanda.R;
import com.austinerck.projectpanda.adapter.TaskAdapter;
import com.austinerck.projectpanda.data.LocalDatabase;
import com.austinerck.projectpanda.data.Project;
import com.austinerck.projectpanda.data.Task;
import java.util.ArrayList;
public class ProjectDetailsActivity extends AppCompatActivity {
private boolean connectionState;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_project_details);
//Sets toolbar and up navigation
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//Gets the connection state from the intent
connectionState = getIntent().getExtras().getBoolean(LocalDatabase.CONNECTION_STATE);
//Gets the projects from the intent
Project project = getIntent().getExtras().getParcelable(LocalDatabase.PROJECT_DETAILS); …Run Code Online (Sandbox Code Playgroud) 我喜欢CollapsingToolbarLayout用RecyclerView,喜欢Whatsapp.
以下是捕获的视频:https://sendvid.com/0oi2lxx5
所以当我向上滚动它没关系,但是当我向下滚动时它不顺畅.我想顺利滚动它RecyclerView.
所以这是我的profile_activity.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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:id="@+id/profile_recyclerview"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_below="@+id/profileactivity_appbar" />
<android.support.design.widget.AppBarLayout
android:id="@+id/profileactivity_appbar"
android:layout_width="match_parent"
android:layout_height="400dp"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme3.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/profileactivity_collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">
<ImageView
android:id="@+id/profileactivity_fullimage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed" />
<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_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
app:layout_anchor="@id/profileactivity_appbar"
app:layout_anchorGravity="bottom|right|end"
app:backgroundTint="@color/ColorPrimary"
android:src="@drawable/ic_create_white_48dp"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
我在用:
compile 'com.android.support:appcompat-v7:23.4.0'
compile …Run Code Online (Sandbox Code Playgroud) android android-recyclerview android-collapsingtoolbarlayout nestedscrollview
我在nestedscrollview内有Recyclerview,我想将nestedscrollview滚动到按钮显示加载中,然后将更多列表加载到recyclerview。
这是我的xml。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="kh.com.iknow.endless.MainActivity">
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Filter"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Sort"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbars="vertical" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 当我运行此代码时,ListView 将具有意外的顶部填充。(见截图)为什么会这样?有办法避免这种情况吗?
\n我已经尝试过 SliverOverlapAbsorber、SafeArea 和 MediaQuery 来修复填充,但到目前为止似乎没有任何效果。
\nimport \'package:flutter/material.dart\';\n\nvoid main() {\n runApp(MyApp());\n}\n\nclass MyApp extends StatelessWidget {\n @override\n Widget build(BuildContext context) {\n return MaterialApp(\n home: MyHomePage(),\n );\n }\n}\n\nclass MyHomePage extends StatelessWidget {\n MyHomePage({Key? key}) : super(key: key);\n\n @override\n Widget build(BuildContext context) {\n return Scaffold(\n body: NestedScrollView(\n headerSliverBuilder: (context, innerBoxIsScrolled) => [\n SliverAppBar(\n pinned: true,\n title: Text(\'Title\'),\n ),\n ],\n body: ListView.builder(\n itemCount: 24,\n itemBuilder: (context, index) => Container(\n height: 40,\n alignment: Alignment.center,\n color: Colors.yellow,\n margin: EdgeInsets.only(top: index != 0 ? …Run Code Online (Sandbox Code Playgroud) dart nestedscrollview flutter flutter-sliver flutter-sliverappbar
我正在尝试显示 slivergridview 视图,如果它始终为全宽,尤其是在大屏幕上,它看起来就不太好
但 CustomScrollView 只接受 sliver 小部件,这使得容器和sizedbox 无法使用。您对此的解决方法是什么?
我正在使用collapsingToolbarlayoutwithnestedscrollview并且它工作正常,直到collapsingToolbarlayout完全崩溃并actionbar显示。这里nestedscrollview停止滚动,一些项目仍然隐藏。
这是我的 xml 文件
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
>
<FrameLayout
android:id="@+id/topLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
>
<ImageView
android:id="@+id/BigThumbnailImage"
android:layout_width="match_parent"
android:layout_height="200dp"
android:adjustViewBounds="true"
android:fitsSystemWindows="true"
android:src="@drawable/bg_health_news"
android:scaleType="fitXY" />
</FrameLayout>
<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_collapseMode="pin" />
</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"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1"
>
<include
android:layout_width="match_parent"
android:layout_height="0dp"
layout="@layout/place_item_details_views"
android:layout_weight="1"
/> …Run Code Online (Sandbox Code Playgroud) 在我的FragmentLayout我LinearLayout有多个子视图(TextView,CardView)。我想找到所有LinearLayout视图的顶部偏移量,但我总是得到零。
这是我的代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_detail, container, false);
nestedScrollView = (NestedScrollView) view.findViewById(R.id.nestedScrollView);
linearLayout = (LinearLayout) view.findViewById(R.id.lll);
int childCount = linearLayout.getChildCount();
int[] location = new int[2];
for (int i = 0; i < childCount; i++) {
View v = linearLayout.getChildAt(i);
v.getLocationOnScreen(location);
Log.e("locX", location[0] + "");
Log.e("locY", location[1] + "");
}
return view;
}
Run Code Online (Sandbox Code Playgroud)
这是我的布局 xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"> …Run Code Online (Sandbox Code Playgroud) nestedscrollview ×10
android ×8
flutter ×2
android-collapsingtoolbarlayout ×1
dart ×1
java ×1
view ×1