向下、向上滑动动画仅在片段中第一次起作用



我已经为片段中的布局实现了一个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>

代码

我在CreateView 中使布局不可见

textViewLayout.setVisibility(View.GONE);
downAnimation = AnimationUtils.loadAnimation(context, R.anim.slide_down);
upAnimation = AnimationUtils.loadAnimation(context, R.anim.slide_up);

然后单击条形图。。。。

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);
}
});

每次显示图表时都需要刷新图表。为此,您需要拨打以下电话。

chartView.invalidate();

最新更新