当我旋转屏幕时,ImageView不会重新缩放图像,但原生Imageview会旋转图像。
我怎样才能做到这一点?
项目https://github.com/jasonpolites/gesture-imageview
清单:
<activity android:name="ScaleTypeCenterInsidePortrait"
android:configChanges="orientation|screenSize"></activity>
我的ScaleTypeCenterInsidePortrait类:
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);
}
}
答案 0 :(得分:1)
在代码中替换这些行
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);
}
}
} 并让你显示这些行
<activity android:name=".Activity_name"
android:configChanges="orientation|keyboardHidden">