У меня есть действие со списком элементов, и когда вы нажимаете на элемент, я хочу, чтобы элементы управления воспроизведением этого элемента скользили вверх из нижней части экрана и становились видимыми.Я определил набор анимации для слайда и слайда, и они работают.Я настроил свой animationListener в своей деятельности и начал мой слайд в анимации при щелчке элемента.Моя проблема в том, что при первом запуске приложения, когда я нажимаю на элемент, выполняется обратный вызов onClick, но анимация не происходит.Второй раз, когда я нажимаю, происходит слайд в анимации, но не слайд.В третий и последующий раз все работает как положено.Вот мои наборы анимации.
vm_slide_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<translate
android:fromYDelta="800"
android:toYDelta="0"
android:duration="600" />
</set>
vm_slide_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<translate
android:fromYDelta="0"
android:toYDelta="800"
android:duration="600" />
</set>
Вот макет моей активности
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/AppBG">
<RelativeLayout
style="@style/LogoBar"
android:id="@+id/logo_bar"
android:layout_alignParentTop="true">
<include layout="@layout/logobar"></include>
</RelativeLayout>
<RelativeLayout
style="@style/TitleBar"
android:id="@+id/title_bar"
android:layout_below="@+id/logo_bar">
<include layout="@layout/titlebar"></include>"
<Button style="@style/TitleBarButton"
android:id="@+id/vm_speaker_btn"
android:text="@string/vm_speaker_btn_label"
android:layout_alignParentLeft="true"
android:layout_margin="4dp">
</Button>
<Button style="@style/TitleBarButton"
android:id="@+id/vm_edit_btn"
android:text="@string/vm_edit_btn_label"
android:layout_alignParentRight="true"
android:layout_margin="4dp">
</Button>
</RelativeLayout>
<ListView
android:id="@+id/@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/title_bar"/>
<RelativeLayout
android:id="@+id/vm_control_panel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/footer"
android:visibility="gone">
<include layout="@layout/vm_control"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<include layout="@layout/taskbar"/>
</RelativeLayout>
</RelativeLayout>
Вот макет для включенного элемента управления
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<RelativeLayout
android:id="@+id/vm_control"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/dark_grey">
<TextView
android:id="@+id/vm_ctl_branding"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:text="@string/branding"
android:textColor="@color/white">
</TextView>
<TextView style="@style/TimeMark"
android:id="@+id/vm_timestamp"
android:layout_toLeftOf="@+id/vm_progress"
android:layout_below="@+id/vm_ctl_branding"
android:layout_marginRight="3dp"
android:text="0:00">
</TextView>
<SeekBar
android:id="@+id/vm_progress"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_below="@+id/vm_ctl_branding"
android:layout_centerHorizontal="true">
</SeekBar>
<TextView style="@style/TimeMark"
android:id="@+id/vm_timeleft"
android:layout_toRightOf="@+id/vm_progress"
android:layout_below="@+id/vm_ctl_branding"
android:layout_marginLeft="3dp"
android:text="-0:00">
</TextView>
<LinearLayout
android:id="@+id/vm_action_button_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/vm_timestamp"
android:layout_alignRight="@+id/vm_timeleft"
android:orientation="horizontal"
android:layout_below="@+id/vm_progress">
<TextView style="@style/Vm_Action_Button"
android:background="@drawable/vm_action_btn_call"
android:id="@+id/vm_callback_btn"
android:layout_marginRight="5dp"
android:text="@string/vm_action_btn_callback">
</TextView>
<TextView style="@style/Vm_Action_Button"
android:background="@drawable/vm_action_btn_delete"
android:id="@+id/vm_delete_btn"
android:layout_marginLeft="5dp"
android:text="@string/vm_action_btn_delete">
</TextView>
</LinearLayout>
</RelativeLayout>
</merge>
Из моего метода onCreate ...
// Handle list item selections
ListView lv = getListView();
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final Voicemail vmItem = (Voicemail) vmla.getItem(position);
Toast.makeText(ctx, "Name: " + vmItem.getCallerName() + " Position: " + position, Toast.LENGTH_SHORT)
.show();
vVm_controls.startAnimation(mSlideIn);
}
});
И моих обратных вызовов анимации ...
@Override
public void onAnimationStart(Animation animation) {
vm_controls_in = !vm_controls_in;
if (vm_controls_in) {
vVm_controls.setVisibility(View.GONE);
} else {
vVm_controls.setVisibility(View.VISIBLE);
// vVm_controls.bringToFront();
}
}
@Override
public void onAnimationEnd(Animation animation) {
if (!vm_controls_in) {
try {
Thread.sleep(1000);
vVm_controls.startAnimation(mSlideOut);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}