1

我遇到了几个页面卷曲动画和 viewflippers 的例子。是否可以通过页面卷曲动画在 viewflipper 的子项之间导航。到目前为止,我应用于 viewflippers 的动画非常基本,例如滑入/滑出,我想知道是否可以使用页面卷曲动画完成/已经实现。

4

2 回答 2

0

这里有一个开源的 android 项目:http ://code.google.com/p/android-page-curl/ 。我在这里找到了另一个:https ://github.com/harism/android_page_curl/ 。

但是,如果这是您所要求的,则没有本机实现。

于 2012-08-17T08:30:40.063 回答
0

为此,您需要从HERE导入一个模块库

之后使用以下代码: -

item_page.xml

<?xml version="1.0" encoding="utf-8"?>
    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/image"
                android:layout_width="200dp"
                android:layout_height="200dp"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:contentDescription="@string/app_name"
                android:scaleType="centerCrop" />

            <TextView
                android:id="@+id/text"
                android:padding="10dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMediumInverse"
                android:textColor="@android:color/black" />
        </LinearLayout>
    </ScrollView>

activity_flipper_view_controller.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:flip="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/darker_gray"
        android:paddingLeft="10dp"
        android:text="@string/header"
        android:textAppearance="@android:style/TextAppearance.Large" />

    <com.aphidmobile.flip.FlipViewController
        android:id="@+id/flip_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        flip:orientation="horizontal" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/darker_gray"
        android:paddingLeft="10dp"
        android:text="@string/footer"
        android:textAppearance="@android:style/TextAppearance.Large" />
</LinearLayout>

FlipperAdapter.java

package pratiksha.com.pagecurlviewdemo;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import pratiksha.com.pagecurlviewdemo.R;

/**
 * Created by User(LPT-APR2015-02) on 11/7/2016.
 */
public class FlipperAdapter extends BaseAdapter {

    private AppCompatActivity appCompatActivity;
    private List<String> strings;
    private int[] drawableIds = {R.mipmap.ic_launcher, R.mipmap.page1, R.mipmap.page2, R.mipmap.ic_launcher,
            R.mipmap.page2, R.mipmap.page1, R.mipmap.page2, R.mipmap.ic_launcher,
            R.mipmap.page1};

    public FlipperAdapter(AppCompatActivity appCompatActivity, List<String> strings) {
        super();
        this.strings = strings;
        this.appCompatActivity = appCompatActivity;
    }

    @Override
    public int getCount() {
        return strings.size();
    }

    @Override
    public String getItem(int position) {
        return strings.get(position);
    }

    @Override
    public long getItemId(int position) {
        return strings.indexOf(getItem(position));
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        LayoutInflater inflater = (LayoutInflater) appCompatActivity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

        // If holder not exist then locate all view from UI file.
        if (convertView == null) {
            // inflate UI from XML file
            convertView = inflater.inflate(R.layout.item_page, parent, false);
            // get all UI view
            holder = new ViewHolder(convertView);
            // set tag for holder
            convertView.setTag(holder);
        } else {
            // if holder created, get tag from view
            holder = (ViewHolder) convertView.getTag();
        }

        holder.textView.setText(getItem(position));
        holder.imageView.setImageResource(drawableIds[position]);

        return convertView;
    }

    private static class ViewHolder {
        private TextView textView;
        private ImageView imageView;

        public ViewHolder(View v) {
            imageView = (ImageView)v.findViewById(R.id.image);
            textView = (TextView) v.findViewById(R.id.text);
        }
    }
}

主要活动.java

package pratiksha.com.pagecurlviewdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.aphidmobile.flip.FlipViewController;

import java.util.ArrayList;

public class FlipperViewController extends AppCompatActivity {

    private FlipViewController flipViewController;
    private FlipperAdapter adapter;
    private ArrayList<String> stringArrayList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_flipper_view_controller);

        flipViewController = (FlipViewController)findViewById(R.id.flip_view);
        stringArrayList = new ArrayList<>();
        readDataFromAssets();

        //create and attach adapter to flipper view
        adapter = new FlipperAdapter(this, stringArrayList);
        flipViewController.setAdapter(adapter);
    }

    private void readDataFromAssets() {
        for(int i=1;i<10;i++)
        stringArrayList.add("Page Number "+i);
    }
}
于 2016-11-07T11:01:44.863 回答