我写了一个CordinatorLayout.Behaviour
类并在CordinatorLayout的子节点中分配它,使用LinearLayout
app:layout_behavior="com.mob2.zd2duta.infodrawer.components. FloatingHeaderBehaviour"
Run Code Online (Sandbox Code Playgroud)
但是只调用layoutDependsOn,onStartNestedScroll,onInterceptTouchEvent回调,不调用rest.我究竟做错了什么
public class FloatingHeaderBehaviour extends CoordinatorLayout.Behavior<LinearLayout> {
private String TAG = FloatingHeaderBehaviour.class.getSimpleName();
private Context context;
public FloatingHeaderBehaviour(Context context, AttributeSet attrs) {
this.context = context;
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, LinearLayout child, View dependency) {
boolean val = (dependency.getId() == R.id.nested_scrollview);
return val;
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, LinearLayout child, View dependency) {
Utils.logD(this.getClass().getSimpleName(), "dependency changed");
return true;
}
@Override
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, LinearLayout child, View directTargetChild, View target, int nestedScrollAxes) {
Utils.logD(this.getClass().getSimpleName(), …
Run Code Online (Sandbox Code Playgroud) android android-design-library androiddesignsupport coordinator-layout android-coordinatorlayout
我有这个布局与协调器布局,其中包含viewpager选项卡,在viewpager适配器中我为每个页面创建了recyclerview.
布局:
08-09 11:28:17.816 2804-2804/com.xxx.yyy.debug E/AndroidRuntime? FATAL EXCEPTION: main
java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.createBitmap(Bitmap.java:638)
at android.graphics.Bitmap.createBitmap(Bitmap.java:620)
at android.support.design.widget.CollapsingTextHelper.ensureExpandedTexture(CollapsingTextHelper.java:413)
at android.support.design.widget.CollapsingTextHelper.setInterpolatedTextSize(CollapsingTextHelper.java:390)
at android.support.design.widget.CollapsingTextHelper.calculateOffsets(CollapsingTextHelper.java:227)
at android.support.design.widget.CollapsingTextHelper.setExpansionFraction(CollapsingTextHelper.java:203)
at android.support.design.widget.CollapsingToolbarLayout$OffsetUpdateListener.onOffsetChanged(CollapsingToolbarLayout.java:768)
at android.support.design.widget.AppBarLayout$Behavior.dispatchOffsetUpdates(AppBarLayout.java:853)
at android.support.design.widget.AppBarLayout$Behavior.setAppBarTopBottomOffset(AppBarLayout.java:836)
at android.support.design.widget.AppBarLayout$Behavior.scroll(AppBarLayout.java:795)
at android.support.design.widget.AppBarLayout$Behavior.onNestedPreScroll(AppBarLayout.java:635)
at android.support.design.widget.AppBarLayout$Behavior.onNestedPreScroll(AppBarLayout.java:583)
at android.support.design.widget.CoordinatorLayout.onNestedPreScroll(CoordinatorLayout.java:1477)
at android.support.v4.view.ViewParentCompat$ViewParentCompatStubImpl.onNestedPreScroll(ViewParentCompat.java:106)
at android.support.v4.view.ViewParentCompat.onNestedPreScroll(ViewParentCompat.java:355)
at android.support.v4.view.NestedScrollingChildHelper.dispatchNestedPreScroll(NestedScrollingChildHelper.java:208)
at android.support.v7.widget.RecyclerView.dispatchNestedPreScroll(RecyclerView.java:8376)
at android.support.v7.widget.RecyclerView.onTouchEvent(RecyclerView.java:2191)
at android.view.View.dispatchTouchEvent(View.java:7205)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2231)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1964)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2237)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1979)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2237)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1979)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2237)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1979)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2237)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1979)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2237)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1979)
at …
Run Code Online (Sandbox Code Playgroud) android android-layout android-recyclerview coordinator-layout
我使用support.v4.widget.NestedScrollView,我的webview有问题.
这是我的布局:
<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/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="@+id/barlayout">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:background="#9E9E9E"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/relativeLayout"
android:animateLayoutChanges="true">
<!-- some views here -->
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<WebView
android:id="@+id/webView"
android:layout_height="match_parent"
android:layout_width="match_parent" />
</android.support.v4.widget.NestedScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/dialog_location"
android:id="@+id/dialog"
android:visibility="invisible"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
有了这个布局,webview必须滚动很多(抱歉链接,我无法发布图片)
https://drive.google.com/open?id=0B7otV-_1sdEvUWRzSjlHY01fY3c
如果我将webview更改为wrap_content,则webview很小
<WebView
android:id="@+id/webView"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
Run Code Online (Sandbox Code Playgroud)
https://drive.google.com/open?id=0B7otV-_1sdEvbVFSRlR0a2IxeUk
android webview coordinator-layout android-coordinatorlayout nestedscrollview
我有一个布局(由android studio生成),我在AppBarLayout中添加了一个RelativeLayout.代码如下,它看起来像这样:
我被卡住的地方:我想要实现的是当滚动Recyclerview时我希望绿色相对布局(具有id'controlContainer')与它一起滚动,当我向上滚动它应该滚动(不仅仅是在顶部但在任何地方我在列表中向上滚动)
顶部的工具栏应保持原样.
<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"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay"
/>
<RelativeLayout
android:id="@+id/controlContainer"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@android:color/holo_green_dark"
app:layout_scrollFlags="scroll|enterAlways"></RelativeLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<include layout="@layout/venue_list" />
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
我认为app:layout_scrollFlags="scroll|enterAlways"
在应该滚动的视图中使用app:layout_behavior="@string/appbar_scrolling_view_behavior"
应该实现,但它没有做任何事情.或者,当我将这些字段添加到工具栏本身时,两个布局都会滚动 - 这不是我想要的,我希望工具栏始终保持固定.
如果有人能指出我在这里正确的方向会很好吗?(我希望有可能使用协调器布局而不是使用onscroll侦听器进行一些布局操作?)
我的应用程序有问题:由于AndroidBug5497解决方案,版本> = Lollipop上的一个奇怪的行为.
我正在使用协调器布局,折叠工具栏,片段,浮动动作按钮和小吃吧,一切都在前棒棒糖上工作正常.我需要在键盘上显示我的Fab,并使用AndroidBug5497解决方法.(根据约瑟夫约翰逊的解决方案)
但是通过这种解决方案,小吃店变得疯狂.我正在使用所有android的支持库23.2.+,并且在我的清单中我已经设置android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
了这个活动
那是我活动的结构:
<Coordinator Layout>
<Collapsing Toolbar />
<Linear Layout>
<Fragment />
</Linear Layout>
<Floating Action Button />
</Coordinator Layout>
Run Code Online (Sandbox Code Playgroud)
这就是片段:
<Linear Layout>
<Nested Scroll View>
<Linear Layout>
<CardView 1/>
<CardView 2/>
<CardView n/>
</Linear Layout>
</Nested Scroll View>
</Linear Layout>
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.非常感谢.
android-layout floating-action-button android-5.0-lollipop android-snackbar coordinator-layout
经典的协调器布局为您提供以下[来源]:
但是,我不希望顶部标题视图滚动,直到它们“成为”固定在顶部的工具栏,下方有阴影。我希望它们全部固定(或固定),但要显示阴影,只有嵌套滚动视图开始在固定视图下滚动。类似于 Marshmallow 设备上的主应用程序抽屉,其中“搜索栏”被固定并且应用程序列表在其下方滚动。
希望我说清楚了。有没有什么简单的方法可以实现,而无需监听滚动事件并手动处理?
编辑
这是我想要实现的目标:
. 请注意右图,因为用户滚动了列表,所以现在在应用列表下方有一个阴影。
谢谢!
我想让自定义视图在滚动过程中随着过渡而折叠。
我有AppBarLayout
一个Toolbar
内部。在此下方,有一个我要折叠的自定义视图。
下面的自定义视图有一个NestedScrollView
用LinearLayout
。
工具栏为绿色,自定义布局为粉红色,线性滚动为灰色:
向下滚动后:
<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.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.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="170dp"
android:layout_marginTop="?attr/actionBarSize"
android:background="@drawable/background"
android:gravity="center">
</RelativeLayout>
<ScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="170dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<include
layout="@layout/linear"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
我应该选择自定义行为,CoordinatorLayout
还是应该NestedScroll
使用翻译动画进行翻译?
android nestedlayout coordinator-layout android-coordinatorlayout android-collapsingtoolbarlayout
我需要在顶部制作一个带有静态视图的可滚动片段,并在底部的每个页面中制作一个带有 RecyclerView 的 ViewPager。我正在尝试使用 CoordinatorLayout 来实现预期的结果,但遇到了一个问题 -当我向上翻转顶部视图(为了向下滚动)并且在向下翻转 RecyclerView 之后(为了向上滚动),滚动是好的抵消和抖动;当我第一次将 Recycler View 向下翻转然后将顶部视图向上翻转时,整个片段会滚动回顶部。当我开始向相反方向滚动时,滚动看起来像是继续而不是停止。
我找到了一个具有类似布局(code)的教程,但是在尝试之后,我发现它遇到了同样的问题。
以下是问题记录:
编辑:在下面添加了布局代码
fragment_layout.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.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.support.design.widget.CollapsingToolbarLayout
android:id="@+id/main.collapsing"
android:layout_width="match_parent"
android:layout_height="200dp"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
app:layout_scrollFlags="scroll|snap"
>
?
<ImageView
android:id="@+id/materialup.profile_backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/picture300x300"
app:layout_collapseMode="parallax"
/>
</android.support.design.widget.CollapsingToolbarLayout>
??
<android.support.v7.widget.Toolbar
android:id="@+id/materialup.toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="24dp"
app:theme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways|snap"
style="@style/Widget.AppCompat.Toolbar"
/>
?
<LinearLayout
android:id="@+id/materialup.title_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="8dp"
android:gravity="center" …
Run Code Online (Sandbox Code Playgroud) android android-scrollview coordinator-layout android-coordinatorlayout android-nestedscrollview
我试图把所有这些元素放在一起,但我看不到FloatingActionButton我的代码是这样的:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="xx.xx.xxxx.xxxxxxxx.Activity.MainFragment">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:scrollbars="vertical" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:src="@drawable/ic_add_white_24dp"
app:fab_colorNormal="@color/btn_accent"
app:fab_colorPressed="@color/btn_accent_pressed"
app:fab_colorRipple="@color/btn_ripple1"
app:fab_shadow="true" />
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
我试图切换SwipeRefreshLayout和CoordinatorLayout位置,然后出现FloatingActionButton,但我无法向上滚动,因为它激活了SwipeRefreshLayout的刷新.我怎么能让它发挥作用?
android swiperefreshlayout floating-action-button android-recyclerview coordinator-layout
我正面临着实施NestedScrollview
内部问题的问题CoordinatorLayout
.请参阅以下布局代码:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:expanded="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:layout_marginTop="?android:attr/actionBarSize"
app:layout_collapseMode="parallax"
android:layout_width="match_parent"
android:weightSum="2"
android:orientation="horizontal"
android:gravity="bottom"
android:fitsSystemWindows="true"
android:background="@color/aop_gray"
android:layout_height="87dp">
<LinearLayout
android:background="#E5E5E5"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent">
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent">
</LinearLayout>
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_anders"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/Custom_red"
style="@style/CustomTheme.CustomActionBar"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
/>
</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"
android:paddingTop="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_horizontal_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="@+id/test1"
android:layout_gravity="fill_vertical"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<com.Custom.saving.widgets.CustomTextView
android:id="@+id/aop_data_overview_form_header"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
style="@style/AopHeader"
android:layout_marginBottom="@dimen/default_margin"
android:text="@string/is_your_data_correct_header" …
Run Code Online (Sandbox Code Playgroud)