我正在创建一个应用。为此,我正在使用Github的Harsim CurlView库。每个页面上只有一个图像,但是我想在每个特定页面中添加一个TextView。完整的代码是用Java编写的。图像的XML代码是用XML编写的。我是初学者。请帮我添加一个TextView。
指向Harish CurlView库的链接:- https://github.com/harism/android-pagecurl
CurlView库的XML代码:- https://github.com/harism/android-pagecurl/blob/master/res/layout/main.xml
curl_activity Java文件:-
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.setBitmapProvider(new BitmapProvider());
mCurlView.setSizeChangedObserver(new SizeChangedObserver());
mCurlView.setCurrentIndex(index);
mCurlView.setBackgroundColor(0xFF202830);
// This is something somewhat experimental. Before uncommenting next
// line, please see method comments in CurlView.
mCurlView.setEnableTouchPressure(true);
// CAGS: This is to allow 2 pages landscape mode, set to false for legacy mode
mCurlView.set2PagesLandscape(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 BitmapProvider implements CurlView.BitmapProvider {
private int[] mBitmapIds = { R.drawable.obama, R.drawable.road_rage, R.drawable.taipei_101, R.drawable.world, R.drawable.color1, R.drawable.logo, R.drawable.man2 };
private String[] mvalues = {"Harsh", "Ishwar", "Sanju", "Amit"};
@Override
public Bitmap getBitmap(int width, int height, int index) {
Bitmap b = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
b.eraseColor(0xFFFFFFFF);
Canvas c = new Canvas(b);
Drawable d = getResources().getDrawable(mBitmapIds[index]);
int margin = 7;
int border = 3;
Rect r = new Rect(margin, margin, width - margin, height - margin);
int imageWidth = r.width() - (border * 2);
int imageHeight = imageWidth * d.getIntrinsicHeight()
/ d.getIntrinsicWidth();
if (imageHeight > r.height() - (border * 2)) {
imageHeight = r.height() - (border * 2);
imageWidth = imageHeight * d.getIntrinsicWidth()
/ d.getIntrinsicHeight();
}
r.left += ((r.width() - imageWidth) ) - border;
r.right = r.left + imageWidth + border + border;
r.top += ((r.height() - imageHeight)) - border;
r.bottom = r.top + imageHeight + border + border;
Paint p = new Paint();
p.setColor(0xFFC0C0C0);
c.drawRect(r, p);
r.left += border;
r.right -= border;
r.top += border;
r.bottom -= border;
d.setBounds(r);
d.draw(c);
return b;
}
@Override
public int getBitmapCount() {
return mBitmapIds.length;
}
}
/**
* CurlView size changed observer.
*/
private class SizeChangedObserver implements CurlView.SizeChangedObserver {
@Override
public void onSizeChanged(int w, int h) {
if (h > w) {
mCurlView.setViewMode(CurlView.SHOW_ONE_PAGE);
mCurlView.setMargins(.01f, .01f, .01f, .01f);
}
}
}