在我的应用程序中,我已将此库https://github.com/armcha/Space-Navigation-View包含在底部导航中,并添加了回收站视图滚动行为
<com.luseen.spacenavigation.SpaceNavigationView
android:id="@+id/space"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:space_background_color="@color/colorPrimary"
app:active_item_color="@color/colorTextPrimary"
app:inactive_item_color="@color/colorWhite"
app:centre_button_color="@color/colorAccent"
app:centre_button_icon="@drawable/ic_camera_white_24dp"
app:inactive_centre_button_icon_color="@color/colorWhite"
app:layout_behavior="com.luseen.spacenavigation.SpaceNavigationViewBehavior" />
我在gradle文件中有mutidexenabled。没有为库添加progaurd规则。他们没有提到要包含的内容。 现在这在调试模式下运行良好。在发布模式下,此操作失败并显示以下错误
Caused by android.view.InflateException
Binary XML file line #40: Could not inflate Behavior subclass com.luseen.spacenavigation.SpaceNavigationViewBehavior
Caused by java.lang.RuntimeException
Could not inflate Behavior subclass com.luseen.spacenavigation.SpaceNavigationViewBehavior
android.support.design.widget.CoordinatorLayout.parseBehavior (SourceFile:628)
android.support.design.widget.CoordinatorLayout$LayoutParams. (SourceFile:2795)
android.support.design.widget.CoordinatorLayout.generateLayoutParams (SourceFile:1703)
android.support.design.widget.CoordinatorLayout.generateLayoutParams (SourceFile:112)
android.view.LayoutInflater.rInflate (LayoutInflater.java:860)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:821)
android.view.LayoutInflater.inflate (LayoutInflater.java:518)
android.view.LayoutInflater.inflate (LayoutInflater.java:426)
android.view.LayoutInflater.inflate (LayoutInflater.java:377)
android.support.v7.app.AppCompatDelegateImplV9.setContentView (SourceFile:287)
android.support.v7.app.AppCompatActivity.setContentView (SourceFile:139)
com.example.MainActivity.onCreate (SourceFile:77)
android.app.Activity.performCreate (Activity.java:6687)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1140)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2631)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2743)
android.app.ActivityThread.-wrap12 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1490)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:154)
android.app.ActivityThread.main (ActivityThread.java:6165)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:888)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:778)
Caused by java.lang.ClassNotFoundException
Didn't find class "com.luseen.spacenavigation.SpaceNavigationViewBehavior" on path: DexPathList[[zip file "/data/app/com.example.dev-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.dev-1/lib/arm, /data/app/com.example.dev-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:56)
java.lang.ClassLoader.loadClass (ClassLoader.java:380)
java.lang.ClassLoader.loadClass (ClassLoader.java:312)
android.support.design.widget.CoordinatorLayout.parseBehavior (SourceFile:621)
android.support.design.widget.CoordinatorLayout$LayoutParams. (SourceFile:2795)
android.support.design.widget.CoordinatorLayout.generateLayoutParams (SourceFile:1703)
android.support.design.widget.CoordinatorLayout.generateLayoutParams (SourceFile:112)
android.view.LayoutInflater.rInflate (LayoutInflater.java:860)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:821)
android.view.LayoutInflater.inflate (LayoutInflater.java:518)
android.view.LayoutInflater.inflate (LayoutInflater.java:426)
android.view.LayoutInflater.inflate (LayoutInflater.java:377)
android.support.v7.app.AppCompatDelegateImplV9.setContentView (SourceFile:287)
android.support.v7.app.AppCompatActivity.setContentView (SourceFile:139)
arrow_right
com.example.MainActivity.onCreate (SourceFile:77)
android.app.Activity.performCreate (Activity.java:6687)
android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1140)
android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2631)
android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2743)
android.app.ActivityThread.-wrap12 (ActivityThread.java)
android.app.ActivityThread$H.handleMessage (ActivityThread.java:1490)
android.os.Handler.dispatchMessage (Handler.java:102)
android.os.Looper.loop (Looper.java:154)
android.app.ActivityThread.main (ActivityThread.java:6165)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:888)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:778)
答案 0 :(得分:1)
我有解决方法:-
package com.luseen.spacenavigation;
import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.View;
/**
* Created by Chatikyan on 13.10.2016.
*/
public class SpaceNavigationViewBehavior<V extends View> extends CoordinatorLayout.Behavior<V> {
public SpaceNavigationViewBehavior(Context context, AttributeSet attrs) {
super();
}
public SpaceNavigationViewBehavior() {
super();
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, V child, View dependency) {
return dependency instanceof Snackbar.SnackbarLayout;
}
@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, final V child, View dependency) {
float translationY = Math.min(0, dependency.getTranslationY() - dependency.getHeight());
child.setTranslationY(translationY);
return true;
}
@Override
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, V child, View directTargetChild, View target, int nestedScrollAxes) {
// Ensure we react to vertical scrolling
return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL
|| super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, nestedScrollAxes);
}
@Override
public void onNestedScroll(final CoordinatorLayout coordinatorLayout, final V child,
final View target, final int dxConsumed, final int dyConsumed,
final int dxUnconsumed, final int dyUnconsumed) {
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
if (dyConsumed > 0) {
Utils.makeTranslationYAnimation(child, child.getHeight());
} else if (dyConsumed < 0) {
Utils.makeTranslationYAnimation(child, 0);
}
}
}