In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the "Android how to use ViewPager to achieve picture sliding preview effect" related knowledge, editor through the actual case to show you the process of operation, the method of operation is simple and fast, practical, I hope that this "how to use ViewPager in Android to achieve picture sliding preview effect" article can help you solve the problem.
Xml Code:
Activity Code:
Package com.example.blog_0615; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity {/ / define an array of pictures private int images [] = {R.drawable.birdMagi R.drawable.catagement R.drawable.pictures} / / define an array of View private List views=new ArrayList (); private ViewPager vp_main_viewpager; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); vp_main_viewpager = (ViewPager) findViewById (R.id.vp_main_viewpager); / / put the pictures in the images array into ImageView for (int I = 0; I < images.length) Class MyAdapter extends PagerAdapter +) {ImageView imageView=new ImageView (this); imageView.setImageResource (images [I]); views.add (imageView);} / / set adapter vp_main_viewpager.setAdapter (new MyAdapter ()) for ViewPager;} class MyAdapter extends PagerAdapter {@ Override public int getCount () {return views.size ();} @ Override public boolean isViewFromObject (View view, Object object) {return view==object } @ Override public Object instantiateItem (ViewGroup container, int position) {View v=views.get (position); container.addView (v); return v;} @ Override public void destroyItem (ViewGroup container, int position, Object object) {View v=views.get (position); / / delete the View container.removeView (v) after the previous picture is crossed } this is the end of the introduction to "how to use ViewPager to achieve picture sliding preview effect in Android". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.