小编Nik*_*pin的帖子

setOnApplyWindowInsetsListener() 未应用填充并调用 2 次

我打电话setOnApplyWindowInsetsListener给我的视图添加填充/边距。我的 XML 包含android:fitsSystemWindows="true"

setOnApplyWindowInsetsListener被调用两次后(第二次插入 0)。

为什么 Android 返回 insets 两次并且第二次 insets 值为零?为什么当我将其设置为第一个值时,我的填充不适用?

代码:

drawer.setOnApplyWindowInsetsListener((v, insets) -> {
            profileButton.setPadding(
                    profileButton.getPaddingLeft(),
                    profileButton.getPaddingTop(),
                    insets.getSystemWindowInsetBottom(),
                    profileButton.getPaddingBottom()
            );
            Timber.d("Inset applied: %d", insets.getSystemWindowInsetBottom());
            return insets;
        });
Run Code Online (Sandbox Code Playgroud)

控制台输出:

D/MainActivity: Inset applied: 53
D/MainActivity: Inset applied: 0
Run Code Online (Sandbox Code Playgroud)

android android-layout android-jetpack android-jetpack-navigation

9
推荐指数
0
解决办法
883
查看次数

如何修复 CameraX 旋转支持

我遇到了 CameraX 屏幕旋转支持的问题。

肖像看图

风景: 看图

转换代码:

private void updateTransform() {
    Log.d(TAG, "updateTransform: ");
    Matrix matrix = new Matrix();

    float centerX = cameraViewTextureV.getWidth() / 2f;
    float centerY = cameraViewTextureV.getHeight() / 2f;

    switch (cameraViewTextureV.getDisplay().getRotation()) {
        case Surface.ROTATION_0:
            rotation = 0;
            break;

        case Surface.ROTATION_90:
            rotation = 90;
            break;

        case Surface.ROTATION_180:
            rotation = 180;
            break;

        case Surface.ROTATION_270:
            rotation = 270;
            break;

        default:
            break;
    }

    matrix.postRotate((float) -rotation, centerX, centerY);

    cameraViewTextureV.setTransform(matrix);
}
Run Code Online (Sandbox Code Playgroud)

所以,正如你在图片中看到的,相机支持屏幕旋转不正确......我updateTransform在屏幕旋转时调用方法......从Android开发者网站的cameraX官方指南中获取此代码。

将非常感谢任何修复建议。祝你今天过得愉快!

android matrix android-jetpack android-camerax

5
推荐指数
1
解决办法
5592
查看次数