将图像添加到 Android Wear 应用程序 - 初学者
Adding image to Android wear app - beginner
我正在开发一个 Android 佩戴应用程序并尝试用图像覆盖文本。
在 main_activity.xml 我有 :
<ImageView
android:id="@+id/myImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher1.png" />
<TextView
android:id="@+id/myImageViewText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/myImageView"
android:layout_alignTop="@id/myImageView"
android:layout_alignRight="@id/myImageView"
android:layout_alignBottom="@id/myImageView"
android:layout_margin="1dp"
android:gravity="center"
android:text="Hello"
android:textColor="#000000" />
Android 工作室抱怨 cannot resolve symbol @drawable/ic_launcher1.png
所以为了修复,我在文件夹 values
中生成了 refs.xml
refs.xml 内容:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="ic_launcher1.png">test</drawable>
</resources>
在哪里添加图片 ic_launcher1.png
?
您不需要 refs.xml
,但您需要文件夹 res
和 res/drawable
以及文件 ic_launcher1.png
位于可绘制文件夹中
你的xml一定是这样的
<ImageView
android:id="@+id/myImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher1" />
你的main_activity.xml一定是这样的:
<ImageView
android:id="@+id/myImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher1" />
<TextView
android:id="@+id/myImageViewText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/myImageView"
android:layout_alignTop="@id/myImageView"
android:layout_alignRight="@id/myImageView"
android:layout_alignBottom="@id/myImageView"
android:layout_margin="1dp"
android:gravity="center"
android:text="Hello"
android:textColor="#000000" />
您不需要 refs.xml 文件。
仅使用 ic_launcher1
不要使用 .png 扩展名
android:src="@drawable/ic_launcher1"
我正在开发一个 Android 佩戴应用程序并尝试用图像覆盖文本。
在 main_activity.xml 我有 :
<ImageView
android:id="@+id/myImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher1.png" />
<TextView
android:id="@+id/myImageViewText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/myImageView"
android:layout_alignTop="@id/myImageView"
android:layout_alignRight="@id/myImageView"
android:layout_alignBottom="@id/myImageView"
android:layout_margin="1dp"
android:gravity="center"
android:text="Hello"
android:textColor="#000000" />
Android 工作室抱怨 cannot resolve symbol @drawable/ic_launcher1.png
所以为了修复,我在文件夹 values
refs.xml
refs.xml 内容:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="ic_launcher1.png">test</drawable>
</resources>
在哪里添加图片 ic_launcher1.png
?
您不需要 refs.xml
,但您需要文件夹 res
和 res/drawable
以及文件 ic_launcher1.png
位于可绘制文件夹中
你的xml一定是这样的
<ImageView
android:id="@+id/myImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher1" />
你的main_activity.xml一定是这样的:
<ImageView
android:id="@+id/myImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher1" />
<TextView
android:id="@+id/myImageViewText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/myImageView"
android:layout_alignTop="@id/myImageView"
android:layout_alignRight="@id/myImageView"
android:layout_alignBottom="@id/myImageView"
android:layout_margin="1dp"
android:gravity="center"
android:text="Hello"
android:textColor="#000000" />
您不需要 refs.xml 文件。
仅使用 ic_launcher1
不要使用 .png 扩展名
android:src="@drawable/ic_launcher1"