我有一些片段,内部视图动态膨胀,并添加到线性布局,以形成类似于列表视图的形式。这在高端设备上运行良好,但在中低级设备上,动画中存在非常明显的延迟,有时动画会被完全跳过。香港专业教育学院曾尝试谷歌搜索一下,并没有遇到任何具体的过渡动画与膨胀视图和提示如何在这样的过程中处理动态视图通胀。
所以回顾一下......用户按下按钮,片段进入视图,视图动态膨胀,动画滞后或被跳过。我真的很想尽可能让一切顺利。
编辑:一些示例代码
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()+"");
}
这取决于我有多少个personObjects在for循环中调用
答案 0 :(得分:1)
1)不要使方法静态(因此您可以访问字段以便以后进行更多优化)
2)缓存布局inflater,这样你就不必为每一行获取
3)如果从XML获取视图,也可以在XML中设置边距和权重
4)从UI线程创建Bundle并在最后时刻设置它或作为回调
5)在其他地方创建你的Fragment,每次onclick被按下时使用相同的片段使用FragmentManager
为此,回调将更轻量级
6)你设置了三个onclick监听器来做同样的事情,你不能只将ImageView点击委托给父母,即只设置点击相对布局
7)完成上述所有操作后,FragmentTransaction是最慢的事情,可能想看看为自定义视图更改它而只是使用可见&进入带有布局动画的onClick
给出一些去的