2016-11-11 8 views
3

Androidのウェアフリーアプリを開発し、テキストを画像にオーバーレイしようとしています。 main_activity.xmlでAndroidウェアアプリに画像を追加する - 初心者

私が持っている:

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

アンドロイドスタジオだからcannot resolve symbol @drawable/ic_launcher1.png

私はフォルダ内のrefs.xmlを生成する修正すると文句を言いvalues

refs.xml内容:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <drawable name="ic_launcher1.png">test</drawable> 
</resources> 

ここで、d o画像を追加するic_launcher1.png

+0

あなたは答えのいずれかをチェックした.pngを使用していけませんか? – gmetax

答えて

2

あなたはrefs.xmlは必要ありませんが、描画可能なフォルダ

Drawable Resources

内であることを、フォルダresres/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" /> 
1
のようにする必要があります

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ファイルは必要ありません。

2

使用が唯一ic_launcher1拡張

android:src="@drawable/ic_launcher1" 
+0

は、drawable、strings、layoutsなどのすべてのリソースのリソースID(R.java内)として扱われるファイル名として使用されるため、拡張子を追加する必要はありません。 – Gaurav

関連する問題