我创建了一个应用程序,它使用了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>
我使用fragmentadapter加载视图:
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;
}
};
答案 0 :(得分:1)
尝试这件事,它可能会起作用
1st 创建一个包含一些静态变量的类,以便我们以后可以使用它
<强> StaticVariables.java 强>
public static ArrayList<ImageView> listOfImageViews = new ArrayList<ImageView>();
第二次现在正常onCreateView
创建imageview
,现在将其传递给我们刚刚创建的静态变量
imageView.setAdjustViewBounds(true);
imageView.getLayoutParams().height = height;
imageView.getLayoutParams().width = width;
....
StaticVariable.listOfImageViews.add(imageview);
3rd 现在在视图分页器上,您的使用添加了一个pageListener并在onPageSelected
上添加动画imageview
并启动动画
mPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
Log.d(LOG_TAG, "onPageSelected " + arg0);
//Create your animation
Animation pulse = AnimationUtils.loadAnimation(getActivity(), R.anim.pulse);
//Start your animation
StaticVariable.listOfImageViews.get(arg0).startAnimation(pulse);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {}
@Override
public void onPageScrollStateChanged(int arg0) {}
});