Search code examples
androidviewgroup

Adding an ImageView in a custom view


I'm trying to have the ImageView appear based on where the user taps in the GameView. I'm getting an error on android:layout_height="300dp" with the message "Error:(15) error: not well-formed (invalid token)." GameView extends ViewGroup. I have onMeasure, onLayout, and onDraw implemented for GameView.

Hovering at the end of these lines shows these error hints:

<com.example.GameView -- Multiple root tags

android:layout_height="300dp" -- Tag start is not closed

<ImageView -- Multiple root tags

<com.example.GameView> -- Unexpected tokens

</LinearLayout> -- Unexpected tokens

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"

    <com.example.GameView
        android:layout_width="match_parent"
        android:layout_height="300dp"

        <ImageView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            />
        </com.example.GameView>

</LinearLayout>

Solution

  • <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
    

    You missed > of LinearLayout.