Я реализовал анимацию slide_down и slide_up для моего макета в моем фрагменте.Я реализовал это для клика в моей гистограмме MPAndroidChart.Проблема в том, что это хорошо работает для первого нажатия на slide_down и slide_up.Для следующих кликов анимация не работает.
slide_down.xml
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="0.0"
android:toXScale="1.0"
android:toYScale="1.0" />
slide_up.xml
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="1.0"
android:toYScale="0.0" />
Макет
<LinearLayout
android:id="@+id/textViewLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/redPrimaryLight"
android:orientation="horizontal"
android:padding="@dimen/_5sdp"
android:weightSum="3">
<TextView
android:id="@+id/txtSelMonth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/white" />
<TextView
android:id="@+id/txtMotor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/white" />
<TextView
android:id="@+id/txtNonMotor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/white" />
</LinearLayout>
код
Я сделал макет невидимым внутри onCreateView
textViewLayout.setVisibility(View.GONE);
downAnimation = AnimationUtils.loadAnimation(context, R.anim.slide_down);
upAnimation = AnimationUtils.loadAnimation(context, R.anim.slide_up);
Затем нажмите barchart ....
gBarChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
textViewLayout.setVisibility(View.VISIBLE);
textViewLayout.setAnimation(downAnimation);
}
@Override
public void onNothingSelected() {
textViewLayout.setAnimation(upAnimation);
textViewLayout.setVisibility(View.GONE);
}
});