按钮不适用于AlexKolpa / fab-toolbar

问题描述 投票:19回答:2

我最近即将导入AlexKolpa/fab-toolbar库,当我注意到动画无效时,即使我按照以下链接中给出的所有指示操作:

https://github.com/AlexKolpa/fab-toolbar

我的代码如下:

主要信息

import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.ObjectAnimator;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.Toast;

import com.github.alexkolpa.fabtoolbar.FabToolbar;


public class MainActivity extends ActionBarActivity implements  View.OnClickListener{


    private FabToolbar fabToolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        fabToolbar = ((FabToolbar) findViewById(R.id.fab_toolbar));

        fabToolbar.setColor(getResources().getColor(R.color.blue));

//        findViewById(R.id.attach).setOnClickListener(this);
        findViewById(R.id.attach).setOnClickListener(new View.OnClickListener(){
            public void onClick(View v){
                Log.e("SOMETHING","SOMETHING");
                fabToolbar.show();
            }
        });

    }

    @Override
    public  void onClick(View v){
        Toast.makeText(this,"This is a button click!", Toast.LENGTH_SHORT).show();
        fabToolbar.hide();
    }

}

主要活动布局:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:tb="http://schemas.android.com/apk/src/org.panel"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

   <!-- <ImageView
        android:id="@+id/policebox"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:cropToPadding="true"
        android:layout_centerInParent="true"
        android:src="@drawable/dot"
        android:text="@string/example1"
        android:onClick="disappearBox" />-->

    <com.github.alexkolpa.fabtoolbar.FabToolbar
        android:id="@+id/fab_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        tb:tb_animation_duration="500"
        tb:tb_button_gravity="end"
        tb:tb_container_gravity="center"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true">

        <ImageView
            android:id="@+id/attach"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_whiteplus"
            android:layout_marginLeft="@dimen/icon_margin"
            android:layout_marginRight="@dimen/icon_margin"
            />

        <!-- More buttons can be added here -->

    </com.github.alexkolpa.fabtoolbar.FabToolbar>

</FrameLayout>

Gradle如果需要:

repositories {
    maven {
        url "https://jitpack.io"
    }
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.gkvxm.animations"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.github.alexkolpa:floating-action-button-toolbar:0.5.1'
    compile 'com.github.ozodrukh:CircularReveal:1.1.0@aar'
    compile 'com.melnykov:floatingactionbutton:1.3.0'
}

关于如何解决这个问题的任何想法?

java android gradle android-animation
2个回答
1
投票

我一直在使用这个库,它完美无缺。我也试过你的代码在Moto X 5.1和Genymotion 4.4上,两个动画都在工作。

虽然有些挑剔:

  • 在布局中,当您使用FrameLayout时,您不需要以下属性: android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true"
  • 您的布局中有一个图像,然后单击该图像,您再次按下该按钮的show。我认为那不是预期的行为。即使你删除那部分,揭示也会正常工作。这部分: findViewById(R.id.attach).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Log.e("SOMETHING", "SOMETHING"); fabToolbar.show(); } });

-1
投票

我刚刚下载了这段代码......

我发现你不知道怎么找id ...

所以,按照这个,它会工作

ImageView imageView;
    imageView= (ImageView) findViewById(R.id.event);
    imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(SampleActivity.this, "Clicked", Toast.LENGTH_SHORT).show();
        }
    });
© www.soinside.com 2019 - 2024. All rights reserved.