自定义悬浮按钮效果实现,带移动效果
来源:互联网 发布:ubuntu怎么安装apache 编辑:程序博客网 时间:2024/05/23 10:54
一个带动画效果的悬浮按钮。从下往上显示,从上往下消失。
代码比较简单,实现原理也比较简单。
public class MainActivity extends Activity {
private Button btn_hide,btn_show;
private Floatingbutton floatingButton ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_hide=(Button)findViewById(R.id.btn_hide);
btn_show=(Button)findViewById(R.id.btn_show);
floatingButton = (Floatingbutton) findViewById(R.id.button_floating_action);
btn_hide.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
floatingButton.hide();
}
});
btn_show.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
floatingButton.show();
}
});
}
}
public class Floatingbutton extends ImageButton {
private Boolean isShow = false;
private static final int TRANSLATE_DURATION_MILLIS = 200;
private final Interpolator mInterpolator = new AccelerateDecelerateInterpolator();
public Floatingbutton(Context context) {
super(context);
}
public Floatingbutton(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public Floatingbutton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs);
}
public void init(Context context, AttributeSet attrs) {
show();
}
public void show() {
if (!isShow) {
isShow = true;
toggle();
}
}
public void hide() {
if (isShow) {
isShow = false;
toggle();
}
}
private void toggle() {
int height = getHeight();
int translationY = isShow ? 0 : height + getMarginBottom();
animate().setInterpolator(mInterpolator)
.setDuration(TRANSLATE_DURATION_MILLIS)
.translationY(translationY);
}
private int getMarginBottom() {
int marginBottom = 0;
final ViewGroup.LayoutParams layoutParams = getLayoutParams();
if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
marginBottom = ((ViewGroup.MarginLayoutParams) layoutParams).bottomMargin;
}
return marginBottom;
}
}
0 0
- 自定义悬浮按钮效果实现,带移动效果
- Android用悬浮按钮实现翻页效果
- Android用悬浮按钮实现翻页效果
- Android用悬浮按钮实现翻页效果
- Android用悬浮按钮实现翻页效果
- Android用悬浮按钮实现翻页效果
- Android用悬浮按钮实现翻页效果
- Android进阶——自定义View之继承系统控件实现自带删除按钮动画效果和软键盘自动悬浮于文本框下方
- Android 自定义PopupWindow实现悬浮窗效果
- RecyclerView实现顶部悬浮条效果 自定义!
- Android 自定义带阴影效果按钮
- 利用ViewDragHelper实现菜鸟裹裹的悬浮按钮效果
- 按钮 CSS3悬浮按钮彩球效果
- Qt实现自定义按钮的三态效果
- Qt实现自定义按钮的三态效果
- Qt实现自定义按钮的三态效果
- 自定义按钮实现水波点击效果
- 自定义按钮实现水波纹效果
- 中国·熙式 X·S蚕丝面膜指尖创造奇迹
- 从Java视角理解CPU上下文切换(Context Switch)
- git 的常规使用
- 选择好ADC中性能指标是设计系统运行良好的必备
- Android 通知栏Notification的整合 全面学习 (一个DEMO让你完全了解它)
- 自定义悬浮按钮效果实现,带移动效果
- 从Java视角理解CPU缓存(CPU Cache)
- Python笔记
- 你好,C++(8)如何表达那些始终保持不变的数据量?3.2.2 常量
- linux 各种后台运行
- 手机app性能测试
- MySQL删除群成员问题
- 队列的实现
- vs2010自动展开选中当前代码所在的文件位置的功能