繁体   English   中英

Android-查看通货膨胀搞乱了片段交易动画

[英]Android - View inflation messes up fragment transaction animation

我有一些片段,这些片段的内部视图被动态放大并添加到linearlayout中,以形成类似于列表视图的形式。 这在高端设备上可以正常工作,但在中低端设备上,动画中存在非常明显的滞后,有时会完全跳过动画。 Ive尝试了一下,在涉及过渡视图的过渡动画方面,还没有遇到任何具体的问题,以及在此过程中如何处理动态视图膨胀的技巧。

因此,回顾一下...。用户按下按钮,就会看到一个片段,视图会动态膨胀,并且动画会滞后或被跳过。 如果可能的话,我真的很想让一切顺利。

编辑:一些示例代码

public static void addPersonRow(PersonObject po){

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 50);
    params.setMargins(0, 5, 0, 5);
    final View view = IncidentReport_v2.ir2.getLayoutInflater().inflate(R.layout.ir_involved_people_row, null);
    view.setLayoutParams(params);
    view.setTag(po.originalName);

    RelativeLayout rl = (RelativeLayout) view.findViewById(R.id.ir_involved_ppl_add_row_rl);

    TextView name = (TextView) view.findViewById(R.id.ir_involved_ppl_name_txt);
    name.setText(po.firstName+" "+po.lastName);

    ImageButton open = (ImageButton) view.findViewById(R.id.ir_involved_ppl_reopen_btn);
    Bundle b = new Bundle();
    b.putParcelable("personObj", po);
    open.setTag(b);
    name.setTag(b);
    rl.setTag(b);

    OnClickListener openClick = new OnClickListener() {

        @Override
        public void onClick(View v) {

            pplAddFrag = new IR_PeopleInvolved_AddForm_Fragment();
            Bundle b = new Bundle();
            b.putParcelable("existingPerson", (Bundle)v.getTag());
            pplAddFrag.setArguments(b);
            android.support.v4.app.FragmentManager fragmentManager = IncidentReport_v2.ir2.getSupportFragmentManager();     
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.setCustomAnimations(R.anim.bounce, R.anim.bounce_out, R.anim.bounce, R.anim.bounce_out);
            fragmentTransaction.add(R.id.ir_main_frame, pplAddFrag, "pplAddFrag");
            fragmentTransaction.addToBackStack("pplAddFrag");
            fragmentTransaction.commit();      

            IncidentReport_v2.theMenu.removeItem(R.id.incident_report_save);
            IncidentReport_v2.ir2.invalidateOptionsMenu();

        }
    };

    open.setOnClickListener(openClick);
    name.setOnClickListener(openClick);
    rl.setOnClickListener(openClick);

    ImageButton delete = (ImageButton) view.findViewById(R.id.ir_involved_ppl_delete_btn);
    delete.setTag(po);
    delete.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            pplHolder.removeView(view);
            IncidentReport_v2.people.remove((PersonObject)v.getTag());
            IR_InvolvedFragment.pplCounterTxt.setText(IncidentReport_v2.people.size()+"");
        }
    });

    pplHolder.addView(view);

    if(!IncidentReport_v2.people.contains(po)){
        IncidentReport_v2.people.add(po);
    }

    IR_InvolvedFragment.pplTxt.setTextColor(IncidentReport_v2.ir2.getResources().getColor(R.color.green));
    IR_InvolvedFragment.pplCounterTxt.setText(IncidentReport_v2.people.size()+"");

}

在for循环中调用此方法,具体取决于我拥有多少personObjects

1)不要将方法设为静态(因此您以后可以访问字段以进行更多优化)

2)缓存布局填充器,因此您不必为每一行都获取它

3)如果您从XML获取视图,则还可以在XML中设置边距和权重

4)在UI线程上创建Bundle,并在最后一刻或将其设置为回调

5)在其他位置创建您的Fragment,每次按下onclick时都使用相同的FragmentManager ,为此使用FragmentManager ,则回调将更加轻巧

6)您设置了三个onclick侦听器来执行相同的操作,您是否可以不仅仅将ImageView的点击委托给父级,也可以仅在相对布局上设置点击

7)完成以上所有操作后,FragmentTransaction才是最慢的操作,可能需要查看将其更改为customview并只使用可见的&在布局动画中的onClick中使用

放手

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM