I have an ImageView that has android:scaleType="fitCenter"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="at.lukle.picturerotation.MainActivity">
<ImageView
android:id="@+id/iv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:src="@drawable/android"/>
<Button
android:id="@+id/btn_rotate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="rotate"/>
</RelativeLayout>
It looks like this:
When the Button gets clicked, I apply a rotation animation:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnRotate = (Button) findViewById(R.id.btn_rotate);
final ImageView iv = (ImageView) findViewById(R.id.iv);
btnRotate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
iv.animate().rotationBy(90f).start();
}
});
}
}
The image gets cut on the side. I want that the scaleType is also applied on the rotated image, so that the ImageView not just gets rotated, but also scaled to fit the width. I guess I need a scaling animation too, but I have no idea how to do that.
I also tried to just use iv.setRotation(90)
, but I have the same problem here...