Skip to content

Compose 没有效果 #457

@louie-wh

Description

@louie-wh

Environment

  • Autosize Version: v1.2.1
  • Target Android Version: Android9.0
  • Device Model: 华为WGR-W09
  • Device Resolution: 2560x1600
  • Design Size On AndroidManifest: 1920 1080

Bug Description:

App 架构为单Activity 多Fragment + Compose 架构,
原生View 有缩放效果,Compose 没有,

Log:

2023-12-11 20:26:06.382 12929-12929 FragmentMain            tech..                      I  SearchView displayMetrics = DisplayMetrics{density=1.3333334, width=2560, height=1600, scaledDensity=1.3333334, xdpi=239.058, ydpi=239.058, densityDpi=213, noncompatWidthPixels=2560, noncompatHeightPixels=1600, noncompatDensity=2.0, noncompatDensityDpi=320, noncompatXdpi=239.058, noncompatYdpi=239.058}
2023-12-11 20:26:06.382 12929-12929 FragmentMain            tech..                      I  SearchView displayMetrics = DensityImpl(density=2.0, fontScale=1.0)
2023-12-11 20:26:06.560 12929-12929 FragmentMain            tech..                      I  SearchView 627.dp = 836.0
2023-12-11 20:26:06.560 12929-12929 FragmentMain            tech..                      I  SearchView 627.dp = 836.0

Compose 在Layout 的时候 dp转 px的时候 使用的是
Density 2
fun Dp.toPx(): Float = value * density
方法。

但是 从日志中可以看到 Compose 的DensityImpl 的density 始终是2.0 没有被修改。

Related Code:

      @Stable
    fun Dp.toPx(): Float = value * density

    /**
     * Convert [Dp] to [Int] by rounding
     */
    @Stable
    fun Dp.roundToPx(): Int {
        val px = toPx()
        return if (px.isInfinite()) Constraints.Infinity else px.roundToInt()
    }

Others:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions