为绘制-XLARGE-MDPI和绘制-sw600dp-MDPI没有重复的资源 [英] Resources for drawable-xlarge-mdpi AND drawable-sw600dp-mdpi without duplication

查看:259
本文介绍了为绘制-XLARGE-MDPI和绘制-sw600dp-MDPI没有重复的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提供相同的图像资源/可绘制到两个绘制-XLARGE-MDPI和绘制-sw600dp-MDPI。

它通过创建两个文件夹下RES /和复制相同的资源集合到每个文件夹似乎我能做到这一点的唯一方法是。

使用布局,我们可以做走样。即创建一个名为layout.xml中值文件的具体预选赛文件夹,并添加条目指向这两个限定词一个布局文件:

  • 价值观XLARGE \ values​​.xml
  • 价值观sw600dp \ values​​.xml

这两个文件的内容会是这样的:

 < XML版本=1.0编码=UTF-8&GT?;
<资源>
    <项目名称=activity_showsTYPE =布局> @布局/ activity_shows_tablet< /项目>
< /资源>
 

(设备匹配XLARGE或设备匹配sw600dp现在将使用activity_shows_tablet.xml作为布局文件activity_shows)

是否有可绘制类似的做法?

解决方案
  

是否有可绘制类似的做法?

它应该完全一样,为布局

png格式的资源投入到默认文件夹

  RES /绘制/ largescreen.png
RES /绘制/ smallscreen.png
 

创建的.xml 资源引用 png格式取值

  RES /绘制/ image.xml
RES /绘制-XLARGE-MDPI / image.xml
RES /绘制-sw600dp-MDPI / image.xml
 

其中, image.xml 有点像(<一href="http://developer.android.com/guide/topics/resources/drawable-resource.html#bitmap-element">documentation)

 &LT; XML版本=1.0编码=UTF-8&GT?;
&LT;位图的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:SRC =@可绘制/ largescreen/&GT;
 

然后使用XML资源,就像使用直接巴布亚新几内亚

 &LT; ImageView的
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_width =WRAP_CONTENT
    机器人:SRC =@可绘制/图像/&GT;
 

I want to provide the same image resources/drawables to both drawable-xlarge-mdpi AND drawable-sw600dp-mdpi.

It seems the only way I can do this is by creating two folders under res/ and copying the same set of resources into each folder.

With layouts we can do aliasing. I.e. creating a file called layout.xml in the values folder with specific qualifiers and adding items to point to a single layout file for both qualifiers:

  • values-xlarge\values.xml
  • values-sw600dp\values.xml

The contents of both files would be something like:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item name="activity_shows" type="layout">@layout/activity_shows_tablet</item>
</resources>

(Devices matching xlarge or devices matching sw600dp would now use activity_shows_tablet.xml as the layout file for "activity_shows")

Is there a similar approach for drawables?

解决方案

Is there a similar approach for drawables?

It should work exactly as it does for layouts

put png resources into the default folder

res/drawable/largescreen.png
res/drawable/smallscreen.png

create .xml resources that refer to the pngs

res/drawable/image.xml
res/drawable-xlarge-mdpi/image.xml
res/drawable-sw600dp-mdpi/image.xml

where image.xml is something like (documentation)

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/largescreen" />

and then use the XML resource as you would use the png directly

<ImageView
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:src="@drawable/image" />

这篇关于为绘制-XLARGE-MDPI和绘制-sw600dp-MDPI没有重复的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆