J'ai un ImageView contenant une image. Cette image est pivotée par des clics de bouton, mais parfois elle devient plus petite ou obtient sa taille d'origine. Je n'ai aucune idée de ce qui cause cela.Changements de taille de bitmap
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
//tablelayout here
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="200dp"
android:maxHeight="200dp"
/>
</LinearLayout>
</RelativeLayout>
paramètres: Initiale
iv = (ImageView)findViewById(R.id.imageView1);
int id = getResources().getIdentifier("landolt", "drawable", getPackageName());
iv.setImageResource(id);
myImg = BitmapFactory.decodeResource(getResources(), R.drawable.landolt);
matrix = new Matrix();
size = 200;
randomize = new Random();
random = randomize.nextInt(8) + 1;
rotate = getAngle(random); //function created by me
matrix.postRotate(rotate);
rotatedBitmap = Bitmap.createBitmap(myImg, 0, 0, myImg.getWidth(), myImg.getHeight(), matrix, true);
iv.setImageBitmap(rotated);
Ainsi, l'image est mis en rotation, pas de changement de taille dans le code.
Une rotation sur le bouton clic:
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (rotate == -90)
{
//rotate back to original direction
old_rotate = -rotate;
matrix.postRotate(old_rotate);
//next rotation
random = randomize.nextInt(8) + 1;
rotate = getAngle(random);
matrix.postRotate(rotate);
rotatedBitmap = Bitmap.createBitmap(myImg, 0, 0, myImg.getWidth(), myImg.getHeight(), matrix, true);
iv.setLayoutParams(new LinearLayout.LayoutParams(size, size));
iv.setImageBitmap(rotated);
}
}
});
Quand je lance l'activité, l'image apparaît avec sa taille d'origine, parfois plus petite. Lorsque je clique sur un bouton, l'image devient plus petite ou devient aussi grande que sa taille d'origine.
Que se passe-t-il?
À quoi ressemble le reste de votre mise en page xml? – CaseyB
Voir le code édité – erdomester
Se pourrait-il que ce soit sur les bords et parce que vous avez android: adjustViewBounds = "true" cela met à l'échelle le tout? – CaseyB