我创建了一个应用程序,它使用 antonyt 的 InfiniteViewpager。
我想在Imageview
创建视图时添加一个动画,但我的动画工作了几次,并非总是如此。这是代码:
public class ColourFragment extends Fragment {
private int identifier;
private String logo;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle args = getArguments();
identifier = args.getInt("identifier");
logo = args.getString("logo");
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View V = inflater.inflate(R.layout.radiologok, container, false);
我ImageView
想要动画。
ImageView imageView = (ImageView)V.findViewById(R.id.radiologovalaszto);
ProgressBar progressBar = (ProgressBar) V.findViewById(R.id.progressBar1);
DisplayMetrics displaymetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels / 4 * 3;
int width = displaymetrics.widthPixels / 4 * 3;
imageView.setAdjustViewBounds(true);
imageView.getLayoutParams().height = height;
imageView.getLayoutParams().width = width;
加载 Android 查询库以从网络获取图像。
AQuery aq = new AQuery(getActivity());
AQUtility.setDebug(true);
aq.hardwareAccelerated11();
图像已设置。
aq.id(imageView).progress(progressBar).image(logo, true, true, width, 0);
在这里我想添加Animation
Animation pulse = AnimationUtils.loadAnimation(getActivity(), R.anim.pulse);
imageView.startAnimation(pulse);
Return V;
}
这是我的动画:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<scale
android:duration="1000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.5"
android:toYScale="0.5" />
<scale
android:duration="1000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="1000"
android:toXScale="2"
android:toYScale="2" />
</set>
我使用片段适配器加载视图:
final PagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public int getCount() {
return Radiologos.length;
}
@Override
public Fragment getItem(int position) {
Fragment fragment = new ColourFragment();
Bundle args = new Bundle();
args.putString("logo", Radiologos[position]);
args.putInt("identifier", position);
fragment.setArguments(args);
return fragment;
}
};