Android: Turn pages up and down, and turn pages up and down

Source: Internet
Author: User

Android: Turn pages up and down, and turn pages up and down

If you achieve up or down the page flip effect, we use this open source project: https://github.com/openaphid/android-flip

Aphid FlipView is a UI component that enables Flipboard paging.

After the download is complete, import it to your current project. Let's go down and flip the pages:



Paste the Code directly:

Layout file:

<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    android:gravity="center"    android:background="@android:color/white" >    <ImageView         android:id="@+id/tv_number"        android:layout_width="wrap_content"        android:layout_height="fill_parent"         android:gravity="center"        android:scaleType="fitXY"       /></LinearLayout></span>

Main file:

<span style="font-size:14px;">public class MainActivity extends Activity {private int[] image=new int[]{R.drawable.qd,R.drawable.qg,R.drawable.qw};private Context activity=this;protected FlipViewController flipViewController;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);flipViewController=new FlipViewController(activity);flipViewController.setAdapter(new baseAdapter());setContentView(flipViewController);}public class baseAdapter extends BaseAdapter{@Overridepublic int getCount() {// TODO Auto-generated method stubreturn image.length;}@Overridepublic Object getItem(int position) {// TODO Auto-generated method stubreturn position;}@Overridepublic long getItemId(int position) {// TODO Auto-generated method stubreturn position;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {// TODO Auto-generated method stubif(convertView==null){convertView=new NumberTextVeiw(activity);}((ImageView)(convertView.findViewById(R.id.tv_number))).setBackgroundResource(image[position]);return convertView;}}private class NumberTextVeiw extends LinearLayout{ViewHolder viewHolder;public NumberTextVeiw(Context context) {super(context);inflate(context, R.layout.text_number_view, this);viewHolder=new ViewHolder();viewHolder.tv_number=(ImageView)findViewById(R.id.tv_number);}}private class ViewHolder {public ImageView tv_number;}}</span>

The above is the code to achieve the effect of turning pages up and down, if you want to achieve page turning between the left and right, you only need to change one code:

<span style="font-size:14px;">flipViewController=new FlipViewController(activity);</span>
Changed:

<span style="font-size:14px;">flipViewController=new FlipViewController(this, FlipViewController.HORIZONTAL);</span>

Reprinted please indicate the source: http://blog.csdn.net/hai_qing_xu_kong/article/details/42215085 sentiment control _






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.