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

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (92)

我目前是新的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');
  });
});
提问于
用户回答回答于

这个动画并不难,你可以很容易地使用Android中的基本动画来执行,并且可以延迟播放。

扫码关注云+社区

领取腾讯云代金券