2016-11-11 97 views
3

我正在開發Android Wear應用程序並嘗試將圖像與文字疊加在一起。將圖像添加到Android Wear應用程序 - 初學者

在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

所以修復我的文件夾中生成refs.xmlvalues

refs.xml內容:

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

其中d o我添加圖像ic_launcher1.png

+0

你檢查任何的答案? – gmetax

回答

2

你不需要refs.xml,但你需要的文件夾resres/drawable和文件ic_launcher1.png是繪製文件夾

Drawable Resources

內,你的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不使用png格式擴展

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

作爲文件名被視爲資源ID(在R.java中)用於所有資源,如可繪製,字符串,佈局等,所以不需要添加只有ID的擴展引用資源 – Gaurav