Page Curl harism - 在布局上使用按钮

时间:2014-02-01 08:26:39

标签: android curl

我正在使用页面curl harism lib在我的应用程序中实现页面卷曲。你可以找到lib here。我已经设法在页面上放置布局而不是图像。但布局不可点击。无法单击布局中的按钮。如何使它们可点击?

活动代码:

package com.Test.pagecurldemo;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

public class CurlActivity extends Activity {

private CurlView mCurlView;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    int index = 0;
    if (getLastNonConfigurationInstance() != null) {
        index = (Integer) getLastNonConfigurationInstance();
    }
    mCurlView = (CurlView) findViewById(R.id.curl);
    mCurlView.setPageProvider(new PageProvider());
    mCurlView.setSizeChangedObserver(new SizeChangedObserver());
    mCurlView.setCurrentIndex(3);
    mCurlView.setBackgroundColor(0x000000);

    // This is something somewhat experimental. Before uncommenting next
    // line, please see method comments in CurlView.
    // mCurlView.setEnableTouchPressure(true);
}

@Override
public void onPause() {
    super.onPause();
    mCurlView.onPause();
}

@Override
public void onResume() {
    super.onResume();
    mCurlView.onResume();
}

@Override
public Object onRetainNonConfigurationInstance() {
    return mCurlView.getCurrentIndex();
}

/**
 * Bitmap provider.
 */
private class PageProvider implements CurlView.PageProvider {

    // Bitmap resources.
    private int[] mBitmapIds = { R.layout.gold, R.layout.bismuth, R.layout.zinc, R.layout.beryllium, R.layout.helium};

    @Override
    public int getPageCount() {
        return 5;
    }

    private Bitmap loadBitmap(int width, int height, int index) {
        LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View v = inflater.inflate(mBitmapIds[index],null);
        v.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));
        v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
        Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(),Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(b);
        v.draw(c);
        return b;
    }

    @Override
    public void updatePage(CurlPage page, int width, int height, int index) {

        switch (index) {
        case 0: {
            Bitmap front = loadBitmap(width, height, 0);
            page.setTexture(front, CurlPage.SIDE_FRONT);
            page.setColor(Color.rgb(49, 79, 79), CurlPage.SIDE_BACK);
            break;
        }
        case 1: {
            Bitmap front = loadBitmap(width, height, 1);
            page.setTexture(front, CurlPage.SIDE_FRONT);
            page.setColor(Color.rgb(49, 79, 79), CurlPage.SIDE_BACK);
            break;
        }
        case 2: {
            Bitmap front = loadBitmap(width, height, 2);
            page.setTexture(front, CurlPage.SIDE_FRONT);
            page.setColor(Color.rgb(49, 79, 79), CurlPage.SIDE_BACK);
            break;
        }
        case 3: {
            Bitmap front = loadBitmap(width, height, 3);
            page.setTexture(front, CurlPage.SIDE_FRONT);
            page.setColor(Color.rgb(49, 79, 79), CurlPage.SIDE_BACK);
            break;
        }
        case 4: {
            Bitmap front = loadBitmap(width, height, 4);
            page.setTexture(front, CurlPage.SIDE_FRONT);
            page.setColor(Color.rgb(49, 79, 79), CurlPage.SIDE_BACK);
            break;
        }
        }
    }

}
/**
 * CurlView size changed observer.
 */
private class SizeChangedObserver implements CurlView.SizeChangedObserver {
    @Override
    public void onSizeChanged(int w, int h) {
        if (w > h) {
            mCurlView.setViewMode(CurlView.SHOW_ONE_PAGE);
            mCurlView.setMargins(.1f, .05f, .1f, .05f);
        } else {
            mCurlView.setViewMode(CurlView.SHOW_ONE_PAGE);
            mCurlView.setMargins(.1f, .1f, .1f, .1f);
        }
    }
}

}

请指导我,因为我不是android的专家。我知道这个问题已在这里提出,但它没有答案。

1 个答案:

答案 0 :(得分:1)

它们不可点击,因为页面只是位图。当您添加布局或按钮时,将绘制位图