Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding image to Android wear app - beginner

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 ?

like image 749
blue-sky Avatar asked Sep 02 '26 23:09

blue-sky


1 Answers

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

Drawable Resources

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" />
like image 154
gmetax Avatar answered Sep 04 '26 17:09

gmetax



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!