如何在android中制作这样的径向浮动动作按钮?

时间:2018-05-30 22:13:26

标签: android android-studio button material-design floating-action-button

我目前刚接触到android设计和材料设计。如果有人可以帮我解决如何制作像这样的径向浮动动作android按钮

,那将是很棒的

https://codepen.io/mblode/pen/pvVpaE

HTML

<div class="container"><div class="row"><div class="col-sm-12">
  <h1 class="text-center">Radial Floating Action Button</h1>
  <p class="text-center">(click)</p>
</div></div></div>

<div class="radial">
  <button class="fa fa-paper-plane fa-3x" id="fa-1"></button>
  <button class="fa fa-home fa-3x" id="fa-2"></button>
  <button class="fa fa-search fa-3x" id="fa-3"></button>
  <button class="fab">
    <div class="fa fa-plus fa-3x" id="plus"></div>
  </button>
</div> 

CSS

@import "compass/css3";

@import url(https://fonts.googleapis.com/css?family=Lato:300,400,700);

$font-stack: 'Lato', sans-serif;

* { box-sizing: border-box; }

$red: #ff4081;

body {
  font-family: $font-stack;
  background: #efefef;
}

button:focus {
  outline: 0;
}

.radial {
  width: 100px;
  height: 100px;
  position: fixed;
  right: 25px;
  bottom: 25px;
  background: $red;
  border-radius: 50%;
  transition: all 0.5s;
  box-shadow: 0px 2px 4px rgba(0,0,0,0.15), 0px 4px 8px rgba(0,0,0,0.2);
}

.fab {
  border: none;
  color: white;
  background-color: #ff4081;
  border-radius: 50%;
  width: 100px;
  height: 100px;
  position: fixed;
  right: 25px;
  bottom: 25px;
  transition: all 0.5s;
  &:hover {
    background-color: darken($red, 15);
  }
}

#plus {
  transition: all 0.5s;
  margin-top: 7px;
}

#fa-1, #fa-2, #fa-3 {
  position: fixed;
  background: transparent;
  border: none;
  right: 60px;
  bottom: 57px;
  transition: all 0.5s;
  color: white;

  &:hover {
   tansition-delay: 0s;
   color: lighten($red, 15); 
  }
}

.radial {
  &.open {
    height: 400px;
    width: 400px;
    right: -125px;
    bottom: -125px;

    .fab {
      background-color: darken($red, 15);
      box-shadow: 0px 2px 4px rgba(0,0,0,0.15), 0px 4px 8px rgba(0,0,0,0.2);
    }

    #plus {
      transform: rotateZ(135deg) translate(-1px, 3px);
    }
    #fa-1 {
      transition-delay: 0s;
      transform: translate(-110px, 10px);
    }
    #fa-2 {
      transition-delay: 0.1s;
      transform: translate(-85px, -85px);
    }
    #fa-3 {
      transition-delay: 0.2s;
      transform: translate(10px, -110px);
    }
  }
}

JS

$(document).ready(function(){
  $('.fab').click (function(){
    $('.radial').toggleClass('open');
  });
});

如果无法开发,一个好的径向浮动动作按钮也可以工作!

1 个答案:

答案 0 :(得分:0)

这个动画并不是那么困难,你可以使用Android中的基本动画轻松地执行此操作并延迟播放。您也可以使用https://github.com/oguzbilgener/CircularFloatingActionMenu,它也有自定义动画选项,但我认为您无法使用此库实现完全相同的动画