为什么ObjectAnimator setDuration不起作用?

时间:2015-06-11 11:39:13

标签: android animation objectanimator

我试图使用RelativeLayoutFragment移到ObjectAnimator内的左侧setDuration

方法setStartDelay()根本不会改变持续时间。

我不是在寻找RelativeLayout layoutConfig2 = (RelativeLayout) rootView1.findViewById(R.id.layoutListConfig2); ObjectAnimator pullLeft = ObjectAnimator.ofFloat(layoutConfig2, "translationX", 0f, -600f); pullLeft.setDuration(4000); // ? pullLeft.start(); 方法

该职位即时更改

onCreateView

这是我的完整@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView1 = inflater.inflate(R.layout.params_config, container, false); ListView listConfiguracoes = (ListView) rootView1.findViewById(R.id.list1_configParameters); ListView listMotor = (ListView) rootView1.findViewById(R.id.list_motor1); final RelativeLayout layoutConfig1 = (RelativeLayout) rootView1.findViewById(R.id.layoutListConfig); final RelativeLayout layoutConfig2 = (RelativeLayout) rootView1.findViewById(R.id.layoutListConfig2); menutitles = getResources().getStringArray(R.array.array1_config); menuIcons = getResources().obtainTypedArray(R.array.arrow_icons); rowItems = new ArrayList<RowItem>(); for (int i = 0; i < menutitles.length; i++) { RowItem items = new RowItem(menutitles[i], menuIcons.getResourceId( i, -1)); rowItems.add(items); } adapter = new CustomAdapter(getActivity(), rowItems, 2); listConfiguracoes.setAdapter(adapter); listMotor.setAdapter(adapter); layoutConfig2.setVisibility(View.VISIBLE); listConfiguracoes.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Animation slide1, slide2; slide1 = AnimationUtils.loadAnimation(getActivity(), R.anim.move_left_slightly); slide2 = AnimationUtils.loadAnimation(getActivity(), R.anim.move_left_fast); switch (position) { case 0: layoutConfig1.startAnimation(slide1); ObjectAnimator pullLeft = ObjectAnimator.ofFloat(layoutConfig2, "translationX", 0f, -600f); pullLeft.setDuration(4000); // ? pullLeft.start(); break; } } }); return rootView1; }

<Link/>

我该如何解决?

2 个答案:

答案 0 :(得分:1)

不能说为什么它不起作用,但这是一个很好的选择。使用ViewPropertyAnimator

layoutConfig2.animate().translationX(-600).setDuration(4000);

ViewPropertyAnimator可以让您的生活更轻松;)。

答案 1 :(得分:1)

我知道这有点晚了,但万一有人碰到这个帖子: 在“开发者选项”下尝试“动画师持续时间刻度”。当我被禁用时,我遇到了这个问题。