2016-11-11 48 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