Android
ViewFlipper
Buscar..
Introducción
Un ViewFlipper
es un ViewAnimator
que cambia entre dos o más vistas que se le han agregado. Solo se muestra un niño a la vez. Si se solicita, ViewFlipper
puede ViewFlipper
automáticamente entre cada niño en un intervalo regular.
ViewFlipper con imagen deslizante
Archivo XML:
<ViewFlipper
android:id="@+id/viewflip"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_weight="1"
/>
Código java:
public class BlankFragment extends Fragment{
ViewFlipper viewFlipper;
FragmentManager fragmentManager;
int gallery_grid_Images[] = {drawable.image1, drawable.image2, drawable.image3,
drawable.image1, drawable.image2, drawable.image3, drawable.image1,
drawable.image2, drawable.image3, drawable.image1
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View rootView = inflater.inflate(fragment_blank, container, false);
viewFlipper = (ViewFlipper)rootView.findViewById(R.id.viewflip);
for(int i=0; i<gallery_grid_Images.length; i++){
// This will create dynamic image views and add them to the ViewFlipper.
setFlipperImage(gallery_grid_Images[i]);
}
return rootView;
}
private void setFlipperImage(int res) {
Log.i("Set Filpper Called", res+"");
ImageView image = new ImageView(getContext());
image.setBackgroundResource(res);
viewFlipper.addView(image);
viewFlipper.setFlipInterval(1000);
viewFlipper.setAutoStart(true);
}
}
Modified text is an extract of the original Stack Overflow Documentation
Licenciado bajo CC BY-SA 3.0
No afiliado a Stack Overflow