androidandroid-jetpack-compose

Compose basic empty view similar to View in android view system


Is there any basic view widget in Compose, similar to the View class or <View>...</View> tag of android view system, to which we can pass a modifier to place it appropriately in a layout and can pass some background to it?


Solution

  • Yes, you can use Box for that.

    Box(
        modifier = Modifier
            .size(100.dp)
            .background(Color.Blue)
            .padding(16.dp)
    ) {
        // your view
    }
    

    If you just need a simple visual gap, or an empty space with a configuration by modifier, you can use Spacer

    Spacer(
        modifier = Modifier
            .size(50.dp)
            .background(Color.Gray)
    )