ilyamuromets
ilyamuromets

Reputation: 413

How to scale ImageView after the orientation is changed?

When I rotate the screen, ImageView doesn't rescale image, but native Imageview rotates the image.
How can I achieve this?

Project https://github.com/jasonpolites/gesture-imageview

Manifest:

<activity android:name="ScaleTypeCenterInsidePortrait"
                  android:configChanges="orientation|screenSize"></activity>

My ScaleTypeCenterInsidePortrait class:

public class ScaleTypeCenterInsidePortrait extends ExampleActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.scale_type_inside_portrait);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    }

}

Upvotes: 1

Views: 1649

Answers (1)

Rajaji subramanian
Rajaji subramanian

Reputation: 288

replace these lines in your code

public class ScaleTypeCenterInsidePortrait extends ExampleActivity {

ImageView imv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
imv=new ImageView(this);
imv.setimageResource(R.drawable."your image name in the drwable folder");
imv.setscaleType(ScaleType.Center_Inside);

    }
@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE){
            setContentView(imv);
        }
        else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
            setContentView(imv);         
        }
    }

} and put you manifest these line

<activity android:name=".Activity_name"
          android:configChanges="orientation|keyboardHidden">

Upvotes: 1

Related Questions