I'm trying to move a RelativeLayout
to the left inside my Fragment
using ObjectAnimator
.
The method setDuration
doesn't change the duration at all.
I'm not looking for setStartDelay()
method
The position is being changed instantaneously:
RelativeLayout layoutConfig2 = (RelativeLayout) rootView1.findViewById(R.id.layoutListConfig2);
ObjectAnimator pullLeft = ObjectAnimator.ofFloat(layoutConfig2, "translationX", 0f, -600f);
pullLeft.setDuration(4000); // ?
pullLeft.start();
Here is my full 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;
}
How can I fix it?
Cant say why its not working, but heres a good alternative. Use
ViewPropertyAnimator
:ViewPropertyAnimator
can make your life easier ;).