I believe thats exactly what I'm doing:
public View getView(int position,
View convertView,
ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi =
(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.lvimages, null);
}
imgFile ii = m_aryImages.get( position );
if ( ii != null ) {
Bitmap bmpData =
BitmapFactory.decodeFile(ii.getFilename());
int intScaledWidth = clsWallpaper.m_intScrWidth / 2;
float fltAspectRatio = (float)bmpData.getHeight() /
(float)bmpData.getWidth();
int intScaledHeight = (int)((float)intScaledWidth *
fltAspectRatio);
Bitmap bmpResized = Bitmap.createScaledBitmap( bmpData,
intScaledWidth,
intScaledHeight,
false );
Drawable drwThumbnail = new BitmapDrawable(bmpResized);
ImageView ivThumbnail =
(ImageView)v.findViewById(R.id.ivthumbNail);
ivThumbnail.setBackgroundDrawable(drwThumbnail);
ii.setThumbnail(ivThumbnail);
// Get the image file name
TextView tvFilename =
(TextView)v.findViewById(R.id.tvFilename);
// Remove the path from the file name
String strFile = ii.getFilename();
int intIdx = strFile.lastIndexOf(File.separator);
if ( intIdx >= 0 ) {
strFile = strFile.substring( intIdx + 1 );
}
tvFilename.setText(strFile);
// Rotation images
ii.setIndex( position );
ii.setupCCW(v.findViewById(R.id.btnCCW));
ii.setupCW(v.findViewById(R.id.btnCW));
}
return v;
}
The methods setupCCW and setupCW add listeners to the buttons:
public void setupCCW(View v) {
m_ibtnCCW = (ImageButton)v;
m_ibtnCCW.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try{
rotateThumbnail(ROTATE_CCW);
} catch( Exception ex ) {
Log.e( TAG, "setOnClickListener", ex );
}
}
});
}
Here is the code for rotateThumbnail():
public void rotateThumbnail(int intRotation) {
try{
if ( intRotation == ROTATE_CW ) {
m_intAngle = 90;
} else if ( intRotation == ROTATE_CCW ) {
m_intAngle = -90;
}
if ( m_intAngle != 0 ) {
// Rotating Bitmap
Drawable drwImg = m_ivThumbnail.getBackground();
Bitmap bmpThumbnail =
((BitmapDrawable)drwImg).getBitmap();
Matrix mtx = new Matrix();
mtx.setRotate(m_intAngle,
bmpThumbnail.getWidth() / 2,
bmpThumbnail.getHeight() / 2);
bmpThumbnail = Bitmap.createBitmap(bmpThumbnail,
0, 0,
bmpThumbnail.getWidth(),
bmpThumbnail.getHeight(),
mtx, true);
Drawable drwRotated = new BitmapDrawable(bmpThumbnail);
m_ivThumbnail.setBackgroundDrawable(drwRotated);
if ( m_intAngle < 0 && m_intTotalAngle == 0 ) {
m_intTotalAngle = 360;
}
m_intTotalAngle = (m_intTotalAngle + m_intAngle) % 360;
}
} catch( Exception ex ) {
Log.e( TAG, "rotateThumbnail", ex );
}
}
As I said in my first post when the buttons are pressed the image is
rotated, but it reverts back to its original state when it goes out of view.
On 02/07/2011 2:20 PM, Mark Murphy wrote:
On Sat, Jul 2, 2011 at 9:07 AM, Simon Platten
<[email protected]> wrote:
I have a listview which has an ImageView in each item and a couple of
buttons. The buttons allow the user to rotate the image clockwise and
counter clockwise by 90 degrees on each press. This works find and the
ImageView is rotated, however if I scroll the item off view, when I scroll
it back into view the orginal image is restored without any rotation
applied, is there a notification that I can get when the item comes into
view so I can correct the image
You are already overriding getView(), presumably. That is where you
apply your rotation.
or....can I modifiy the original ImageView
in the list view directly?
You are already overriding getView(), presumably. That is where you
are modifying "the original ImageView", so that is where you apply
your rotation.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en