Did Google update the DrawImage portion of the jetpack compose API?

  • Thread starter greySky
  • Start date
  • Tags
    Google
In summary, the tutorial explains how to add a picture to a composable function in Jetpack Compose. It uses the DrawImage function to display an image and shows how to import it using the +imageResource syntax. However, some users may encounter errors when trying to use this function, which can be fixed by adding the appropriate dependencies in the build.gradle file.
  • #1
greySky
4
2
https://developer.android.com/jetpack/compose/tutorial
in the "Add a picture" section

Code:
@Composable
fun NewsStory(){
    val image = +imageResource(R.drawable.header)
    Column (modifier = Spacing(64.dp)){
        Text("A day in shark fin cove")
        Text("davenport")
        Text("december 2018")
        DrawImage(image)
    }
}

Hovering over DrawImage shows: "Unresolved reference: DrawImage", There is no auto import option for this error as there was with "Column" earlier in the tutorial.

I am using Android Studio 4.0 Canary 8
Is my local setup or the linked tutorial out of date? what is the current method to add an image

PS
I actually had two problems, "R.drawable.header" had some error I cannot remember the error text for this error but applying
https://stackoverflow.com/a/49743044
fixed the issue with R.drawable.header", but the DrawImage error persisted.
 
Technology news on Phys.org
  • #2
found the answer:
build.gradle (:app) [excerpt]:
dependencies {

...
    implementation 'androidx.ui:ui-material:0.1.0-dev03'
    implementation 'androidx.ui:ui-foundation:0.1.0-dev03'
    implementation 'androidx.ui:ui-tooling:0.1.0-dev03'
...

}

Line 5 was missing in the default build.gradle (:app). Adding the line enables the auto-add-import-statement option (under alt-enter like most jetbrains IDEs)

I suppose adding the line for "foundation" (after searching the androidx reference for DrawImage)
https://developer.android.com/reference/kotlin/androidx/ui/foundation/package-summary
would make sense to experienced developers. However following a naive path through the existing tutorial and setup instructions does not make this obvious.
 
  • Like
Likes jim mcnamara

What is the jetpack compose API?

The jetpack compose API is a toolkit developed by Google for building native Android user interfaces. It allows developers to easily create and manage UI components using a declarative approach.

What is the DrawImage portion of the jetpack compose API?

The DrawImage portion of the jetpack compose API is a function that allows developers to draw images on the screen. It is used to display images within the user interface of an Android app.

Has Google updated the DrawImage portion of the jetpack compose API?

Yes, Google has recently updated the DrawImage portion of the jetpack compose API. The latest update includes performance improvements and bug fixes.

What are the benefits of the updated DrawImage portion of the jetpack compose API?

The updated DrawImage portion of the jetpack compose API offers improved performance, which results in faster rendering of images on the screen. It also includes bug fixes, ensuring a smoother and more stable experience for developers.

How can I access the updated DrawImage portion of the jetpack compose API?

The updated DrawImage portion of the jetpack compose API is available for download through the Android Studio SDK Manager. Make sure to update your Android Studio to the latest version to access the updated API.

Back
Top