【问题标题】:Change view's alpha with respect to another view's width相对于另一个视图的宽度更改视图的 alpha
【发布时间】:2017-02-18 07:09:01
【问题描述】:

我在工具栏下方(不是顶部)有一个工具栏和一个导航抽屉。当用户向右滑动打开导航抽屉时,我喜欢淡入工具栏中的文本视图。我想要与打开多少抽屉以及朝哪个方向相关的淡入/淡出效果。例如,打开时,工具栏中的标题文本视图应淡入。关闭时,工具栏中的标题应淡出。如果用户在抽屉打开 %50 时停止滑动,则 textview 的 alpha 也应该在 %50 处停止。任何帮助将不胜感激。

【问题讨论】:

    标签: android android-animation alpha-transparency


    【解决方案1】:

    您可以使用this 回答并执行以下操作:

    View myText = findViewById(R.id.toolbarText) // replace with your text id
    mDrawerToggle = new ActionBarDrawerToggle(
            this,                 
            mDrawerLayout,        
            R.drawable.ic_drawer,  
            R.string.drawer_open,  
            R.string.drawer_close  
    ) {    
        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
                 myText.setAlpha(slideOffset); //As easy as this line
            }
    };
    

    【讨论】:

    • 有时您看不到代码中的内容 :( 谢谢!
    猜你喜欢
    • 2015-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多