0

我使用https://github.com/makovkastar/FloatingActionButton

布局:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:fab="http://schemas.android.com/apk/res-auto"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?android:attr/actionBarSize"
            />

    <!-- The main content view -->
    <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/swipeRefreshLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
                     android:layout_width="match_parent"
                     android:layout_height="match_parent">
            <com.melnykov.fab.ObservableScrollView
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:id="@+id/obsScrollView">
                <LinearLayout
                        android:orientation="vertical"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:background="#edeff2">
                    ...
                </LinearLayout>
            </com.melnykov.fab.ObservableScrollView>
            <com.melnykov.fab.FloatingActionButton
                    android:id="@+id/fab"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom|right"
                    android:layout_margin="16dp"
                    android:src="@drawable/ic_favorite_grey600_48dp"
                    fab:fab_colorNormal="@color/primary"
                    fab:fab_colorPressed="@color/primary_pressed"
                    fab:fab_colorRipple="@color/ripple"/>
        </FrameLayout>
    </android.support.v4.widget.SwipeRefreshLayout>

</LinearLayout>

代码:

...
// ScrollView
scrollView = (ObservableScrollView) findViewById(R.id.obsScrollView);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.attachToScrollView(scrollView);
fab.setColorNormal(getResources().getColor(R.color.primary));
fab.setColorPressed(getResources().getColor(R.color.primary_pressed));
...

但是当我参加此活动时出现错误:

01-08 19:44:01.371    2311-2311/com.example.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.myapp, PID: 2311
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapp/com.example.myapp.VideoActivity}: android.view.InflateException: Binary XML file line #23: Error inflating class com.melnykov.fab.ObservableScrollView
...
Caused by: android.view.InflateException: Binary XML file line #23: Error inflating class com.melnykov.fab.ObservableScrollView

请告诉我,我做错了什么

应用程序编译没有错误

依赖项:

在此处输入图像描述 在此处输入图像描述

当我在 XML 中设置 attr 时:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:fab="http://schemas.android.com/apk/res-auto"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
...
<com.melnykov.fab.FloatingActionButton
                    android:id="@+id/fab"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom|right"
                    android:layout_margin="16dp"
                    android:src="@drawable/ic_favorite_grey600_48dp"
                    fab:fab_colorNormal="@color/primary"
                    fab:fab_colorPressed="@color/primary_pressed"
                    fab:fab_colorRipple="@color/ripple"/>
...

错误:

Error:(137, -1) android-apt-compiler: [myapp] /Users/fedor/IdeaProjects/myapp/res/layout/video.xml:137: error: No resource identifier found for attribute 'fab_colorNormal' in package 'com.example.myapp'
Error:(137, -1) android-apt-compiler: [myapp] /Users/fedor/IdeaProjects/myapp/res/layout/video.xml:137: error: No resource identifier found for attribute 'fab_colorPressed' in package 'com.example.myapp'
Error:(137, -1) android-apt-compiler: [myapp] /Users/fedor/IdeaProjects/myapp/res/layout/video.xml:137: error: No resource identifier found for attribute 'fab_colorRipple' in package 'com.example.myapp'

但我导入了库

可观察滚动视图:

package com.melnykov.fab;


import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;

public class ObservableScrollView extends ScrollView {

    public interface OnScrollChangedListener {
        void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt);
    }

    private OnScrollChangedListener mOnScrollChangedListener;

    public ObservableScrollView(Context context) {
        super(context);
    }

    public ObservableScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ObservableScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        if (mOnScrollChangedListener != null) {
            mOnScrollChangedListener.onScrollChanged(this, l, t, oldl, oldt);
        }
    }

    public void setOnScrollChangedListener(OnScrollChangedListener listener) {
        mOnScrollChangedListener = listener;
    }
}
4

2 回答 2

1

我开始使用 Gradle,它解决了所有问题

于 2015-01-14T17:56:20.683 回答
0

在您的 XML 文件中添加xmlns:fab="http://schemas.android.com/tools". 这将修复“未找到属性的资源标识符...”错误。

于 2016-12-14T03:08:28.357 回答