2017-02-02 57 views
0

我有一个创建帐户按钮的活动。点击该按钮后,它会执行一个向上滑动的动画。这是缓慢和波涛汹涌。我已经在nexus 4模拟器以及Galaxy s7边缘上测试过了。我试过在asynctask上运行它,但它没有改善动画。改善android片段动画性能

有没有一种方法可以提高动画效果?

创建帐户按钮的onclick方法:

public void createAccount(View v) { 
    Log.i("Login", "Create Account button tapped."); 

    new AsyncTask<Void, Void, Void>() { 

     @Override 
     protected Void doInBackground(Void... params) { 

      FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); 
      transaction.setCustomAnimations(R.anim.slide_up, 0); 
      transaction.add(R.id.create_account_frame_layout, new CreateAccountFragment()).commit(); 
      return null; 
     } 

     @Override 
     protected void onPostExecute(Void aVoid) { 
      super.onPostExecute(aVoid); 
     } 
    }.execute(); 

} 

CreateAccountFragment类:

import android.support.v4.app.Fragment; 

public class CreateAccountFragment extends Fragment { 

    public CreateAccountFragment() { 

    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 

     View rootView = inflater.inflate(R.layout.create_account_background, container, false); 

     return rootView; 

    } 

} 

回答

0

原来我的问题是不是与动画。动画表现较差的原因是因为我仅为我的所有应用程序的背景提供了一张图像。

因此,图像的大小调整了一个昂贵的过程。

我通过提供多个背景图像解决了该问题,为mipmap文件夹中的每个dpi调整了大小。