[英]Adding an ImageView in a custom view
我试图根据用户在GameView
点击的位置显示ImageView
。 我在android:layout_height="300dp"
上遇到错误,并显示消息"Error:(15) error: not well-formed (invalid token)."
GameView
扩展了ViewGroup
。 我有onMeasure
, onLayout
和onDraw
实施了GameView
。
将鼠标悬停在这些行的末尾会显示以下错误提示:
<com.example.GameView
多个根标签
android:layout_height="300dp"
-标签开始未关闭
<ImageView
多个根标签
<com.example.GameView>
-意外令牌
</LinearLayout>
-意外令牌
<?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>
我认为您有语法错误。 com.example.GameView未正确关闭。 应该是这样的。
<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
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"
您错过了>
LinearLayout。
最终布局应如下所示。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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_width="wrap_content"
android:layout_height="wrap_content" />
</com.example.GameView>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.