![]() ![]() This change will be made in the Kotlin code. Don't worry about this warning for now because later in the codelab, you will be setting the content description of the ImageView based on what dice image you're displaying. You may notice a warning on the ImageView in the Component Tree that says to add a content description to your ImageView. ![]() This centers the ImageView vertically in the ConstraintLayout.Īll the warnings about constraints should now be gone.Īfter all that, the Design view should look like this, with the ImageView in the center and the Button just below it. Now select the ImageView again and add a vertical constraint connecting the bottom of the ImageView to the bottom of the parent.The Button will slide up beneath the ImageView. Add a vertical constraint to the Button, connecting the top of the Button to the bottom of the ImageView.The ImageView will slide up to the top of the ConstraintLayout. Add a vertical constraint to the ImageView, connecting the top of the ImageView to the top of the parent.This will horizontally center the ImageView within the parent. Connect the right side of the ImageView to the right edge of the parent.Connect the left side of the ImageView to the left edge of the parent ConstraintLayout. Add horizontal constraints to the ImageView.You need to vertically center the ImageView in the screen, regardless of where the Button is located. Now you need to position the ImageView and the Button below it. The Button is not vertically constrained because you removed the TextView below which it was originally positioned. The Button is not vertically constrained, and the ImageView is neither vertically nor horizontally constrained. In the Component Tree, you will notice two errors.The Design view of your app should look like this. This is the temporary image you will use until you add the dice images in the next task. In the Pick a Resource dialog, select avatars under Sample data.Drag an ImageView from the Palette onto the Design view, positioning it above the Button.Ignore the warning on the Button for now.Right-click and choose Delete or press the Delete key.In that case, you can select a View by selecting it in the Component Tree instead. Tip: As you add more UI components and are adding and removing constraints, you may temporarily find one View overlapping another, making it hard to select the one in the back. In the Layout Editor, select the TextView in the Component Tree.Open activity_main.xml ( app > res > layout > activity_main.xml).You can use the solution code or the code you created. Open and run the Dice Roller app from the previous codelab in Android Studio.In this task, you'll replace the TextView in your layout with an ImageView that displays an image of the dice roll result. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |