2015-01-09 3 views
0

Я использую https://github.com/makovkastar/FloatingActionButtonОшибка при наполнении класса 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 

Пожалуйста, скажите m е, что я делаю неправильно

приложение компилируется без ошибок

Зависимости:

enter image description here enter image description here

Когда я установил Attr в XML:

<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' 

но я импортировал библиотеку

ObservableScrollView:

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; 
    } 
} 
+0

У вас есть правильное пространство имен в вашем xml? Можете ли вы опубликовать его полностью? – Opiatefuchs

+0

Я обновил сообщение. –

+0

http://stackoverflow.com/questions/3948934/synchronise-scrollview-scroll-positions-android попробуйте это –

ответ

1

Я начал использовать Gradle и решить все проблемы,

0

В файле XML добавить xmlns:fab="http://schemas.android.com/tools". Это устранит ошибки «Нет идентификатора ресурса, найденного для атрибута ...».

Смежные вопросы