-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