自从Google为启动器图标添加了mipmap文件夹后,我在使用drawable文件夹时遇到了问题。我手动将hdpi文件夹添加到了drawable文件夹中,但当我尝试添加src路径时,这些图片无法被查看和选择。我该如何将drawable文件夹中的图像添加到Android Studio 1.2中的ImageView中?
自从Google为启动器图标添加了mipmap文件夹后,我在使用drawable文件夹时遇到了问题。我手动将hdpi文件夹添加到了drawable文件夹中,但当我尝试添加src路径时,这些图片无法被查看和选择。我该如何将drawable文件夹中的图像添加到Android Studio 1.2中的ImageView中?
尝试使用以下代码方式,有三种方法可以在ImageView上设置图像。
imageView.setImageResource(R.drawable.play);
或者
<ImageView
android:id="@+id/ivProfileBg"
android:src="@drawable/image_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/ivProfileBg"
android:background="@drawable/image_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<项目名称>\app\src\main\res\drawable\
(如果不存在drawable目录,请创建一个新的)。 <ImageView
android:id="@+id/ivProfileBg"
android:src="@drawable/image_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
其中,image_name 是你刚刚粘贴到 drawable 目录中的 PNG 图像的名称。
如果你想将图像粘贴到 hdpi 部分,你必须在 res\
文件夹下创建该目录,然后路径将是 <Project-Name>\app\src\main\res\drawable-hdpi\
在drawable文件夹内添加hdpi文件夹是行不通的,因为Android无法发现它。为了更方便地导航,您可以将Project Explorer从“Android”切换到“Project”,如下所示:
: