I want to use an Android Gallery but draw the items from right to left (the writing direction in Hebrew) The Gallery items represent chapters in a book written in Hebrew, so that the item order is important
Android draws them in the opposite direction like this (the first item is chosen) 1 2 3 4 5
instead of this 5 4 3 2 1
I already tried overriding these methods in my Gallery class (none of them changed the drawing order):
@Override
public int getChildDrawingOrder(int childCount, int i) {
return getChildDrawingOrder(childCount, childCount - i+1)
}
I know from Debugging that the getChildDrawingOrder was visited I tried a couple of variations of this, but non of them worked
I also tried
@Override
public 开发者_如何学运维void onDraw(Canvas canvas) {
canvas.save();
canvas.rotate(180, getWidth()/2, getHeight()/2);
super.onDraw(canvas);
canvas.restore();
}
I'll be happy if anyone can help me with this I can't get this right
Thank you Very Much Oron
Feed the Gallery with images using an ImageAdapter class and load the images in reverse order e.g.
gallery = (Gallery) findViewById(R.id.gallery);
Integer[] mImageIds = new Integer[] {
R.drawable.chapter_5_image,
R.drawable.chapter_4_image,
R.drawable.chapter_3_image,
R.drawable.chapter_2_image,
R.drawable.chapter_1_image};
imageAdapter = new ImageAdapter(this, mImageIds);
gallery.setAdapter(imageAdapter);
The ImageAdapter class should extend android.widget.BaseAdapter - there are plent of example around showing how to implement an adapter of this type.
Also, set the initial selection in the gallery as follows:
gallery.setSelection(4, true);
This should position the gallery to show the Chapter 1 image.
精彩评论