java - Android 应用程序不合理地旋转为横向,然后又返回纵向

标签 java android android-studio

Android 应用程序不合理地瞬间旋转至横向,然后又返回纵向。从相机返回应用程序时会发生这种情况。

    public void configureItemImageButton() {
    MaterialCardView itemImageButton = (MaterialCardView) view.findViewById(R.id.itemImageCardView);
    itemImageButton.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v){
            Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent, 111);
        }
    });
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 111) {
        Bitmap image = (Bitmap) data.getExtras().get("data");
        ImageView imageview = (ImageView) view.findViewById(R.id.itemImage);
        imageview.setImageBitmap(image);
    }
}

下面是我的 Android list 文件:

    <application
    android:allowBackup="true"
    android:icon="@drawable/ic_trainsterlogo"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:screenOrientation="portrait">
    <activity android:name=".TrainsterActivity"
        android:theme="@style/AppTheme.NoActionBar"
        android:windowSoftInputMode="adjustNothing"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.CAMERA"> </uses-permission>

编辑:如果我的 editTextview 中有文本,则不会出现此问题,但是我无法再重现此问题,并且我尝试删除 textview 但问题仍然存在。

编辑:我已经通过保存实例消除了清除图像的负面影响。然而,无法解释的旋转在美学上仍然令人不快。

最佳答案

将此添加到 list 文件中该特定 Activity 下

  android:screenOrientation="portrait"

关于java - Android 应用程序不合理地旋转为横向,然后又返回纵向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57862041/

相关文章:

java - PHP 的 oAuth 客户端模块

android - 如何复制 Google Chrome Android App 的 header 行为

java - 控制台应用程序中出现延迟加载错误

java - 如何使 Moqui 屏幕上的链接 url 是相对的而不是绝对的?

java - 通过c3p0在mysql中查询超时

java - Android:图像保存到位置

java - 如何去除中心点下方的阴影?

java - Android studio 不同屏幕尺寸像素

Android 开发 - 新 Activity 开放太快

Android 模拟器渲染问题 - macOS Big Sur 更新后