鉴于我正在使用这样的布局:
<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    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.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/flexible_space_image_height"
        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="match_parent"
            android:fitsSystemWindows="true"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:statusBarScrim="@android:color/transparent"
            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.v7.widget.RecyclerView
        android:id="@+id/mainView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        />
    <android.support.design.widget.FloatingActionButton
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_marginBottom="20dp"
        app:fabSize="normal"
        app:layout_anchor="@id/appbar"
        app:layout_anchorGravity="bottom|center_horizontal"
        />
</android.support.design.widget.CoordinatorLayout>
这几乎是标准的Cheesesquare样本 - 除了FloatingActionButton,我想提升大约20dp.
但是,这不起作用.无论我使用边距,填充等 - 按钮将始终以锚点的边缘为中心,如下所示:

如何将FAB按预期向上移动20dp?
我在FloatingActionButtona Recyclerview中显示a CoordinatorLayout,当单击FAB时,将添加一行Recyclerview.现在问题是当我在API 15中测试时FAB有余量,但是当我在API 22(棒棒糖5.1.1-Nexus 4)中测试时,我没有得到任何余量并且FAB被按到屏幕的边缘.
我担心的是FAB在API 15中有默认的边距设置(没有测试其他设备)但在API 22中没有,或者我错过了什么.
我的布局代码:
<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:background="#6fbababa"
    android:fitsSystemWindows="true">
    <android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:paddingBottom="@dimen/fab_padding_bottom"
        android:scrollbars="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#ffffff">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:orientation="horizontal"
            app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
            ---------------------
            ---------------------    
        </LinearLayout>
    </android.support.design.widget.AppBarLayout>
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/button_floating_action"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:src="@drawable/ic_plus"
        app:borderWidth="0dp"
        app:layout_anchor="@id/my_recycler_view"
        app:layout_anchorGravity="bottom|right|end"
        app:rippleColor="@color/wallet_highlighted_text_holo_light" />
</android.support.design.widget.CoordinatorLayout>

android floating-action-button androiddesignsupport coordinator-layout android-coordinatorlayout
我很确定这是一个bug,所以我要求解决方法.我的布局如下:
<CoordinatorLayout>
    <AppBarLayout>
        <CollapsingToolbarLayout>
            <ImageView/>
            <Toolbar/>
        </CollapsingToolbarLayout>
    </AppBarLayout>
    <android.support.v4.widget.NestedScrollView/> <!-- content here -->
</CoordinatorLayout>
我正在从网上检索内容,我不知道它有多高 - 可能是几行,可能很长.但是,我发现CollapsingToolbar当内容不足以覆盖整个屏幕时效果不佳.案例:
content.height > screen.height:工作; 滑动顶部/底部展开和折叠工具栏,以及滚动内容;
content.height < screen.height:没有.这是不是好,因为大部分的时间(content.height + expandedToolbar.height) > screen.height!
换句话说,当内容不够高时,即使内容+ expandedToolbar比整个屏幕高得多,它也不会对滚动手势做出反应并显示一些错误 - 可能需要十个手势来折叠工具栏一点点.因此,您很难到达内容的底部,因为工具栏已展开,所以内容隐藏在底部.
任何解决方法?
如果你想尝试,只需采取cheesesquare示例项目并删除(或减少)NestedScrollViewactivity_detail.xml中的内容[API17 here]
android android-support-library android-design-library androiddesignsupport
我最近将支持设计库更新到最新版本,现在每个具有CollapsingToolbarLayout抛出以下异常的活动:
    java.lang.NoSuchMethodError: No static method setLayoutDirection(Landroid/graphics/drawable/Drawable;I)V in class Landroid/support/v4/graphics/drawable/DrawableCompat; or its super classes (declaration of 'android.support.v4.graphics.drawable.DrawableCompat' appears in /data/data/com.radioafrica.music/files/instant-run/dex/slice-com.android.support-support-v4-24.0.0-beta1_f8cf3ba4c70f87f407a745b9fa14a2205d0b587c-classes.dex)
完整的错误日志如下:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.radioafrica.music/com.radioafrica.music.activity.PlaylistTracks}: android.view.InflateException: Binary XML file line #31: Binary XML file line #31: Error inflating class android.support.design.widget.CollapsingToolbarLayout at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
    at android.app.ActivityThread.-wrap11(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:148) 
    at android.app.ActivityThread.main(ActivityThread.java:5417) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NoSuchMethodError: No static method setLayoutDirection(Landroid/graphics/drawable/Drawable;I)V in class Landroid/support/v4/graphics/drawable/DrawableCompat; or its super classes (declaration of …android androiddesignsupport android-collapsingtoolbarlayout
我尝试了从新的android支持设计库中的navigationView.我想要一个动态的headerview.基本上,我的标题视图将显示当天的报价.我喜欢大约10个引号,我想随机选择一个引用并在headerView的textview中显示.我还想为headerView添加onClick方法.
现在,我没有看到任何以编程方式更改headerview布局的可能性.有任何建议来实现吗?
android navigation-drawer android-design-library navigationview androiddesignsupport
我正在使用com.android.support:design:23.1.0库中的浮动操作按钮(fab)组件来生成我的应用程序的工厂.
但是我第一次使用fab.hide()加载一个新活动,并在点击一个按钮后尝试通过fab.show()显示图标,那么fab没有动画.这仅在加载新活动后第一次发生.当我多次尝试隐藏并显示按钮时,它会正常动画.
这是什么问题?在加载活动后立即对其进行动画制作也很有魅力.
活动中的Java:
    fabSend = (FloatingActionButton) findViewById(R.id.fabSend);
    fabSend.hide();    
CompoundButton.OnCheckedChangeListener changeChecker = new CompoundButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked){
//                FAB on
                fabSend.show();
            }   else {
//                FAB off
                fabSend.hide();
            }
        }
    };
Layout.xml
            <android.support.design.widget.FloatingActionButton
                android:id="@+id/fabSend"
                app:borderWidth="0dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="end"
                android:layout_alignParentBottom="true"
                android:layout_marginRight="@dimen/fab_margin"
                android:layout_marginBottom="54dp"
                android:src="@drawable/ic_check_white_24dp" />
animation android android-activity android-design-library androiddesignsupport
我用新的android.support.v4.widget.NestedScrollView和我面对的问题.
这是我的布局:
<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="250dp">
    <android.support.design.widget.CollapsingToolbarLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.7">
             <!-- some views inside -->
        </RelativeLayout>
        <android.support.v7.widget.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:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    >
    <WebView
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</android.support.v4.widget.NestedScrollView>
我需要在textView中加载html,所以我做:
content.setText(Html.fromHtml(htmlString));
它看起来很奇怪.我的textview放在屏幕的底部.

在我滑动文本后,它开始看起来正常.

我认为textview不仅仅是对这些问题的看法.我尝试使用webview,但它甚至没有显示内容(我认为由于高度计算不正确).所以我需要webview或textview来纠正工作NestedScrollView.
PS如果我设置textview高度dp然后文本看起来正确,但我需要wrap_content高度.
最后我需要使用WebView.Alex Facciorusso回答部分有效,但我遇到了另一个问题.当WebView内容有一些特定的高度,那么我可以看到部分内容,但我不能向下滚动.例:

一直试图找到一些有关新设计支持库所需规则的信息,以便通过proguard.我找不到任何有关它的信息.
结束使用这些规则:
-keep class android.support.design.widget.** { *; }
-keep interface android.support.design.widget.** { *; }
-dontwarn android.support.design.**
这些规则似乎有效,但我不确定是否有更好的规则或它是否适用于设计支持库中的所有类
我在CollapsingToolBar里面使用CoordinatorLayout,我NestScrollView包含一些EditText作为子视图.我面临的是当edittext聚焦并且keybaoard出现时我的完整视图没有向上滚动.
下面是代码和图像作为该布局的输出.
<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/app_bar_height"
    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:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">
        <ImageView
            android:id="@+id/ivProductImage"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:src="@drawable/stub_image"
            app:layout_collapseParallaxMultiplier="0.7"
            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/ThemeOverlay.AppCompat.Light" />
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
    android:id="@+id/nested_scroll_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">
    <LinearLayout
        android:id="@+id/containerLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp">
            <EditText
                android:id="@+id/etProductTitle"
                style="@style/EditTextStyle"
                android:hint="@string/lbl_product_title"
                android:inputType="text"
                android:textSize="24dp" />
        </android.support.design.widget.TextInputLayout>
        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp">
            <EditText
                android:id="@+id/etProductDescription"
                style="@style/EditTextStyle"
                android:hint="@string/lbl_description"
                android:inputType="text" />
        </android.support.design.widget.TextInputLayout>
        <LinearLayout
            android:layout_width="match_parent" …android androiddesignsupport android-coordinatorlayout android-collapsingtoolbarlayout
我正在使用Google Design Support Library 25.0.0在我的活动中,我有一个相对布局
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
现在当我引用它来添加BottomSheetBehaviour时,我收到错误
java.lang.IllegalArgumentException: The view is not associated with BottomSheetBehavior
这是布局:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/maps_colayout"
xmlns:app="http://schemas.android.com/tools"
android:fitsSystemWindows="true"
android:background="@color/white">
...
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="280dp"
    android:layout_gravity="bottom"
    android:id="@+id/rl_bottomsheet"
    android:background="#F3F3F3"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
    ...
</RelativeLayout>
这是活动相关代码:
CoordinatorLayout colayout = (CoordinatorLayout) findViewById(R.id.maps_colayout);
    View bottomSheet = colayout.findViewById(R.id.rl_bottomsheet);
    BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
    behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
        @Override
        public void onStateChanged(@NonNull View bottomSheet, int newState) {
            // React to state change
        }
        @Override
        public void onSlide(@NonNull View bottomSheet, float slideOffset) {
            // React to dragging …android android-design-library androiddesignsupport bottom-sheet