簡體   English   中英

像在Gmail應用中切換帳戶的動畫

[英]Animation like switching accounts in Gmail App

Gmail應用導航視圖

將點擊的圖像翻譯為活動帳戶圖像,並將活動帳戶圖像從其位置淡入淡出到點擊圖像的位置。

每當有人談論物化導航抽屜時,我都喜歡這個庫的功能, 是非常有用的。 你絕對可以實現它是屏幕截圖。

在此輸入圖像描述

在此輸入圖像描述

它是一個高度可定制的,我們幾乎在4個項目中使用它,我對它非常滿意。 在這里閱讀 我不太確定動畫,但你可以實現這一點,因為它是非常可定制的庫

使用帶有布局的動畫效果,並根據需要制作它。 我建議你按照對我有用的教程,我將它用於動畫。

動畫導航示例

https://github.com/mxn21/FlowingDrawer

動畫的按鈕效果

其他有用

https://github.com/XXApple/AndroidLibs/blob/master/%E5%B8%83%E5%B1%80Layout/README.md

它是Ravi Bro的古老但常青的例子。

http://www.androidhive.info/2013/06/android-working-with-xml-animations/

正如我發現這個鏈接。 https//github.com/HeinrichReimer/material-drawer

在此鏈接中, NavigationDrawer演示使用Switch Account技術,您需要更改帳戶。

為此,您可以通過單擊Small round corner選擇您的帳戶,如在屏幕截圖(+2) ,右側打開DropDown ,您可以選擇您必須去的帳戶。

依賴性:

Gradle依賴:

repositories {
    // ...
    maven { url 'https://jitpack.io' }
}
dependencies {
    compile 'com.heinrichreimersoftware:material-drawer:2.3.2'
}

如何使用 :

第1步:讓您的Activity擴展DrawerActivity:

public class MainActivity extends DrawerActivity {}

第2步:設置您的內容:

setContentView(R.layout.activity_main);

第3步:設置個人資料:

drawer.setProfile(
        new DrawerProfile()
                .setRoundedAvatar((BitmapDrawable)getResources().getDrawable(R.drawable.profile_avatar))
                .setBackground(getResources().getDrawable(R.drawable.profile_cover))
                .setName(getString(R.string.profile_name))
                .setDescription(getString(R.string.profile_description))
                .setOnProfileClickListener(new DrawerProfile.OnProfileClickListener() {
                    @Override
                    public void onClick(DrawerProfile drawerProfile, long id) {
                        Toast.makeText(MainActivity.this, "Clicked profile #" + id, Toast.LENGTH_SHORT).show();
                    }
                })
        );

第4步:填充抽屜列表:

drawer.addItem(
        new DrawerItem()
                .setImage(getResources().getDrawable(R.drawable.ic_first_item))
                .setTextPrimary(getString(R.string.title_first_item))
                .setTextSecondary(getString(R.string.description_first_item))
                .setOnItemClickListener(new DrawerItem.OnItemClickListener() {
                    @Override
                    public void onClick(DrawerItem drawerItem, long id, int position) {
                        Toast.makeText(MainActivity.this, "Clicked first item #" + id, Toast.LENGTH_SHORT).show();
                    }
                })
        );
drawer.addDivider();
drawer.addItem(
        new DrawerItem()
                .setImage(getResources().getDrawable(R.drawable.ic_second_item))
                .setTextPrimary(getString(R.string.title_second_item))
                .setOnItemClickListener(new DrawerItem.OnItemClickListener() {
                    @Override
                    public void onClick(DrawerItem drawerItem, long id, int position) {
                        Toast.makeText(MainActivity.this, "Clicked second item #" + id, Toast.LENGTH_SHORT).show();
                    }
                })
        );

第5步:為您的主題添加actionBarStyle:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/color_primary</item>
    <item name="colorPrimaryDark">@color/color_primary_dark</item>
    <item name="colorAccent">@color/color_accent</item>
    <item name="actionBarStyle">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>

步驟6(可選):更改抽屜主題:

抽屜根據您選擇的應用主題獲取主題,但您也可以修改它。

setDrawerTheme(
        new DrawerTheme(this)
                .setBackgroundColorRes(R.color.background)
                .setTextColorPrimaryRes(R.color.primary_text)
                .setTextColorSecondaryRes(R.color.secondary_text)
                .setTextColorPrimaryInverseRes(R.color.primary_text_inverse)
                .setTextColorSecondaryInverseRes(R.color.secondary_text_inverse)
                .setHighlightColorRes(R.color.highlight)
);

步驟7(可選):設置您自己的工具欄:

您可以像使用ActionBarActivity一樣設置自己的工具欄。

setSupportActionBar(toolbar);

輸出:

在此輸入圖像描述

在此輸入圖像描述

希望這能幫助你快樂編碼......

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM