Reputation: 53816
I'm developing an Android wear app and attempting to overlay text with an image.
In main_activity.xml I have :
<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 studio complains that cannot resolve symbol @drawable/ic_launcher1.png
So to fix I generate refs.xml
in folder values
refs.xml content :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="ic_launcher1.png">test</drawable>
</resources>
Where do I add the image ic_launcher1.png
?
Upvotes: 3
Views: 850
Reputation: 3763
use only ic_launcher1
dont use .png extension
android:src="@drawable/ic_launcher1"
Upvotes: 2
Reputation: 3973
You don't need refs.xml
, but you need folders res
and res/drawable
and the file ic_launcher1.png
to be inside the drawable folder
and your xml must be like that
<ImageView
android:id="@+id/myImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher1" />
Upvotes: 2
Reputation: 11326
Your main_activity.xml must be like this:
<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" />
You don't need the refs.xml file.
Upvotes: 1