真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Android中FloatingActionButton實(shí)現(xiàn)懸浮按鈕實(shí)例

Android中FloatingActionButton(懸浮按鈕) 使用不是特別多,常規(guī)性APP應(yīng)用中很少使用該控件. 當(dāng)然他的使用方法其實(shí)很簡單.直接上代碼:

成都創(chuàng)新互聯(lián)公司自2013年起,先為鐘山等服務(wù)建站,鐘山等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為鐘山企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

xml:

<?xml version="1.0" encoding="utf-8"?>


  

  

    

      

      
    

    

      

      
    

    

      

      
    
  

  

MainActivity:

package com.example.liupanpan.floatingactionbuttondemo;

import android.animation.AnimatorInflater;
import android.animation.AnimatorSet;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  private CheckBox cbDelay;
  private FloatingActionButton fab01Add;
  private boolean isAdd = false;
  private RelativeLayout rlAddBill;
  private int[] llId = new int[]{R.id.ll01, R.id.ll02, R.id.ll03};
  private LinearLayout[] ll = new LinearLayout[llId.length];
  private int[] fabId = new int[]{R.id.miniFab01, R.id.miniFab02, R.id.miniFab03};
  private FloatingActionButton[] fab = new FloatingActionButton[fabId.length];
  private AnimatorSet addBillTranslate1;
  private AnimatorSet addBillTranslate2;
  private AnimatorSet addBillTranslate3;
  private AnimatorSet addBillTranslate4;
  private AnimatorSet addBillTranslate5;
  private AnimatorSet addBillTranslate6;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.basic_fab_activity);
    initView();
    setDefaultValues();
    bindEvents();
  }

  private void initView() {
    cbDelay = (CheckBox) findViewById(R.id.cbDelay);
    fab01Add = (FloatingActionButton) findViewById(R.id.fab01Add);
    rlAddBill = (RelativeLayout) findViewById(R.id.rlAddBill);
    for (int i = 0; i < llId.length; i++) {
      ll[i] = (LinearLayout) findViewById(llId[i]);
    }
    for (int i = 0; i < fabId.length; i++) {
      fab[i] = (FloatingActionButton) findViewById(fabId[i]);
    }
  }

  private void setDefaultValues() {
    addBillTranslate1 = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.add_bill_anim);
    addBillTranslate2 = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.add_bill_anim);
    addBillTranslate3 = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.add_bill_anim);
//    addBillTranslate4 = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.add_bill_anim);
//    addBillTranslate5 = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.add_bill_anim);
//    addBillTranslate6 = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.add_bill_anim);
  }

  private void bindEvents() {
    fab01Add.setOnClickListener(this);
    for (int i = 0; i < fabId.length; i++) {
      fab[i].setOnClickListener(this);
    }
  }

  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.fab01Add:
        fab01Add.setImageResource(isAdd ? R.mipmap.ic_launcher_round : R.mipmap.ic_launcher_round);
        isAdd = !isAdd;
        rlAddBill.setVisibility(isAdd ? View.VISIBLE : View.GONE);
        if (isAdd) {
          addBillTranslate1.setTarget(ll[0]);
          addBillTranslate1.start();
          addBillTranslate2.setTarget(ll[1]);
          addBillTranslate2.setStartDelay(cbDelay.isChecked() ? 50 : 0);
          addBillTranslate2.start();
          addBillTranslate3.setTarget(ll[2]);
          addBillTranslate3.setStartDelay(cbDelay.isChecked() ? 100 : 0);
          addBillTranslate3.start();
//          addBillTranslate4.setTarget(ll[3]);
//          addBillTranslate4.setStartDelay(cbDelay.isChecked() ? 250 : 0);
//          addBillTranslate4.start();
//          addBillTranslate5.setTarget(ll[4]);
//          addBillTranslate5.setStartDelay(cbDelay.isChecked() ? 300 : 0);
//          addBillTranslate5.start();
//          addBillTranslate6.setTarget(ll[5]);
//          addBillTranslate6.setStartDelay(cbDelay.isChecked() ? 350 : 0);
//          addBillTranslate6.start();
        }
        break;
      case R.id.miniFab01:
        hideFABMenu();
        break;
      case R.id.miniFab02:

        hideFABMenu();
        break;
      case R.id.miniFab03:
        hideFABMenu();
        break;
      default:
        break;

    }
  }

  private void hideFABMenu() {
    rlAddBill.setVisibility(View.GONE);
    fab01Add.setImageResource(R.mipmap.ic_launcher_round);
    isAdd = false;
  }
}

運(yùn)行程序,就可以實(shí)現(xiàn)當(dāng)前的效果.問題XML的圖片請自己替換一下,demo就不上傳了.

效果如下:

Android中FloatingActionButton實(shí)現(xiàn)懸浮按鈕實(shí)例

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。


分享標(biāo)題:Android中FloatingActionButton實(shí)現(xiàn)懸浮按鈕實(shí)例
網(wǎng)站鏈接:http://weahome.cn/article/ghijej.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部