我想提供相同的图像资源/可绘制到两个绘制-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
![Android应用开发技术 用户界面 界面导航设计](https://p.xsw88.cn/allimgs/daicuo/20230906/1048.png)
创建的.xml
资源引用 png格式
取值
RES /绘制/ image.xml
RES /绘制-XLARGE-MDPI / image.xml
RES /绘制-sw600dp-MDPI / image.xml
其中, image.xml
有点像(documentation)
< XML版本=1.0编码=UTF-8&GT?;
<位图的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:SRC =@可绘制/ largescreen/>
然后使用XML资源,就像使用直接巴布亚新几内亚
< ImageView的
机器人:layout_height =WRAP_CONTENT
机器人:layout_width =WRAP_CONTENT
机器人:SRC =@可绘制/图像/>
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-xlargevalues.xml values-sw600dpvalues.xmlThe 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 png
s
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" />
相关推荐
最新文章