-1
A
回答
1
我们使用fabAction库:
编译 'com.github.shell软件:FAB:1.0.5'
https://github.com/shell-software/fab
我们的XML是这样的:
<RelativeLayout
android:id="@+id/news_item_actions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="@dimen/fab_margin"
android:layout_marginBottom="@dimen/fab_margin"
android:orientation="vertical"
android:visibility="visible"
>
<com.software.shell.fab.ActionButton
android:id="@+id/news_item_share_sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="0dp"
app:button_color="@color/share_sms"
app:image="@drawable/share_button_sms"
/>
<com.software.shell.fab.ActionButton
android:id="@+id/news_item_share_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="70dp"
app:button_color="@color/share_email"
app:image="@drawable/share_button_mail"
/>
<com.software.shell.fab.ActionButton
android:id="@+id/news_item_share_twitter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="140dp"
app:button_color="@color/share_twitter"
app:image="@drawable/share_button_twitter"
/>
<com.software.shell.fab.ActionButton
android:id="@+id/news_item_share_facebook"
android:layout_width="36dp"
android:layout_height="36dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="210dp"
app:button_color="@color/share_facebook"
app:image="@drawable/share_button_facebook"
/>
<com.software.shell.fab.ActionButton
android:id="@+id/news_item_share_dummy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="280dp"
app:button_color="@color/share_cancel"
app:image="@drawable/share_button_cancel"
/>
</RelativeLayout>
我们的Java代码是这样的:
final ActionButton actionButton = (ActionButton) findViewById(R.id.news_item_action_button);
final ActionButton actionCancelButton = (ActionButton) findViewById(R.id.news_item_action_cancel_button);
actionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
expand(findViewById(R.id.news_item_share_facebook), 1);
expand(findViewById(R.id.news_item_share_twitter), 2);
expand(findViewById(R.id.news_item_share_email), 3);
expand(findViewById(R.id.news_item_share_sms), 4);
actionCancelButton.setVisibility(View.VISIBLE);
actionButton.setVisibility(View.GONE);
}
});
actionCancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
collapse(findViewById(R.id.news_item_share_facebook), 1);
collapse(findViewById(R.id.news_item_share_twitter), 2);
collapse(findViewById(R.id.news_item_share_email), 3);
collapse(findViewById(R.id.news_item_share_sms), 4);
actionCancelButton.setVisibility(View.GONE);
actionButton.setVisibility(View.VISIBLE);
}
});
public void expand(final View v, int pos) {
v.setVisibility(View.VISIBLE);
RelativeLayout.LayoutParams paramsTemp = (RelativeLayout.LayoutParams)v.getLayoutParams();
float d = getResources().getDisplayMetrics().density;
final int expectedMove = paramsTemp.topMargin - mMargins[pos-1];//(int)((ACTION_SIZE*pos) * d);
final int[] topMargin = {paramsTemp.topMargin,mMargins[pos-1]};
Animation a = new Animation()
{
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)v.getLayoutParams();
if(interpolatedTime == 1){
params.setMargins(params.leftMargin, topMargin[1],params.rightMargin,params.bottomMargin);
v.setLayoutParams(params);
}else{
int addedMargin = (int)(expectedMove * interpolatedTime);
int marginTop = topMargin[0] - addedMargin;
params.setMargins(params.leftMargin, marginTop,params.rightMargin,params.bottomMargin);
v.setLayoutParams(params);
}
}
@Override
public boolean willChangeBounds() {
return true;
}
};
// 1dp/ms
a.setInterpolator(new DecelerateInterpolator(1.0f));
a.setDuration(750);
v.startAnimation(a);
}
/*
* This method is use to animate the collapse of share actions in this activity.
* @param (final View v) The view which will be expanded.
*/
public void collapse(final View v, int pos) {
RelativeLayout.LayoutParams paramsTemp = (RelativeLayout.LayoutParams)v.getLayoutParams();
final int[] topMargin = {paramsTemp.topMargin};
float d = getResources().getDisplayMetrics().density;
final int expectedMove = (int)((ACTION_SIZE*pos) * d);
Animation a = new Animation()
{
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
if(interpolatedTime == 1){
v.setVisibility(View.GONE);
}else{
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)v.getLayoutParams();
int addedMargin = (int)(expectedMove * interpolatedTime);
int marginTop = topMargin[0] + addedMargin;
params.setMargins(params.leftMargin, marginTop,params.rightMargin,params.bottomMargin);
v.setLayoutParams(params);
}
}
@Override
public boolean willChangeBounds() {
return true;
}
};
// 1dp/ms
a.setInterpolator(new AccelerateInterpolator(1.0f));
a.setDuration(750);
v.startAnimation(a);
}
这就是我们如何使动画作品。希望它有效。
相关问题
- 1. 动画隐藏按钮
- 2. Toogle动画隐藏显示按钮jquery
- 3. 的UISearchBar动画隐藏按钮
- 4. 按钮,隐藏背景动画
- 5. 隐藏和动画显示按钮,iphone
- 6. 带代码隐藏圆角的按钮
- 7. HTML按钮:代码隐藏操作
- 8. 添加OnClick到代码隐藏按钮
- 9. 添加asp:代码隐藏按钮
- 10. 使用ASP.Net命令按钮隐藏或隐藏代码隐藏编码
- 11. 添加RotateTransform动画代码隐藏
- 12. 的WinRT /地铁动画代码隐藏
- 13. Android:隐藏其他活动的按钮
- 14. ASP.Net在代码隐藏的调用代码隐藏功能的按钮
- 15. 隐藏按钮,Android的
- 16. UWP:触发器切换按钮在代码隐藏中点击动画
- 17. 动画隐藏图像android
- 18. 自动隐藏按钮
- 19. 动画按钮Android
- 20. 隐藏按钮
- 21. 隐藏按钮
- 22. 当按下按钮时显示和隐藏动画图像
- 23. Android登录按钮隐藏按下
- 24. Android:在按钮上隐藏键盘按
- 25. Android - 由Android界面隐藏的按钮
- 26. Android:按钮移动动画
- 27. 脉动按钮动画android
- 28. 在代码隐藏中添加按钮代理内部的按钮
- 29. 与代码隐藏动态
- 30. 使用Webview滚动时隐藏浮动按钮隐藏
我不希望你为我做。我没有经验的android。所以我想知道如何做到这一点。谢谢。 – martur94