blue-sky
blue-sky

Reputation: 53816

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 ?

Upvotes: 3

Views: 850

Answers (3)

Gaurav
Gaurav

Reputation: 3763

use only ic_launcher1 dont use .png extension

android:src="@drawable/ic_launcher1"

Upvotes: 2

gmetax
gmetax

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

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" />

Upvotes: 2

Ros&#225;rio P. Fernandes
Ros&#225;rio P. Fernandes

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

Related Questions