应用不透明度时的性能问题

时间:2017-04-24 15:08:44

标签: android performance android-layout android-fragments

我正在开发一个Android应用程序,其活动背景有4个片段,每个片段我都有小部件(布局有按钮等)。
问题是当我对这些小部件应用不透明度时,片段之间的移动变得非常慢。 (没有不透明度,一切都很完美)
以前有人遇到过这个问题,或者有人有什么建议吗?
提前致谢


后台xml文件:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/tab_activity_background"
android:tileMode="disabled" />

obacity:

private void setWidgetBackgroundColor()
{
    GradientDrawable backgroundDrawable = new GradientDrawable();
    backgroundDrawable.setSize(WIDGET_WIDTH, WIDGET_HEIGHT);
    backgroundDrawable.setColor(getResources().getColor(bgColorResId));
    backgroundDrawable.setCornerRadius(WIDGET_CORNER_RADIUS);
    if(MINDOGLASS_ENABLED)
    {
        backgroundDrawable.setAlpha(opacity);
    }

    if (Build.VERSION.SDK_INT >= 16)
    {
        setBackground(backgroundDrawable);
    }
    else
    {
        setBackgroundDrawable(backgroundDrawable);
    }
}

片段:

private class MainFragmentsAdapter extends FragmentStatePagerAdapter
{

    Class[] classes = {FavoritesFragment.class, ControlsFragment.class, ActionsFragment.class, RulesFragment.class, GroupsFragment.class};
    Map<Integer, WeakReference<TileGridTabFragment>> currentFragments = new HashMap<>();
    FragmentManager supportFragmentManager;


    public MainFragmentsAdapter(FragmentManager supportFragmentManager)
    {
        super(supportFragmentManager);
        this.supportFragmentManager = supportFragmentManager;
    }

    @Override
    public Fragment getItem(int position)
    {
        try
        {
            TileGridTabFragment fragment = (TileGridTabFragment)classes[position].newInstance();
            fragment.setActivity(DevicesActivity.this);
            currentFragments.put(position, new WeakReference<>(fragment));
            return  fragment;
        }
        catch (InstantiationException e)
        {
            return null;
        }
        catch (IllegalAccessException e)
        {
            return null;
        }
    }

    @Override
    public int getCount()
    {
        return classes.length;
    }

    public TileGridTabFragment getFragment(int key)
    {
        WeakReference<TileGridTabFragment> tileGridTabFragmentWeakReference = currentFragments.get(key);
        if(tileGridTabFragmentWeakReference == null)
        {
            return null;
        }
        return tileGridTabFragmentWeakReference.get();
    }
}}

没有不透明度: without opacity

不透明度: with opacity

0 个答案:

没有答案