Resources for drawable-xlarge-mdpi and drawable-sw600dp-mdpi without duplication

I want to provide the same image resources / drawings for both drawable-xlarge-mdpi and drawable-sw600dp-mdpi.

It seems the only way to do this is to create two folders under res / and copy the same set of resources to each folder.

With layouts, we can do smoothing. That is, by creating a file called layout.xml in the values ​​folder with specific qualifiers and adding elements to indicate one layout file for both determinants:

  • Values-XLarge \ values.xml
  • Values-sw600dp \ values.xml

The contents of both files will look something like this:

<?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 will now use activity_shows_tablet.xml as the layout file for "activity_shows")

Is there a similar approach for drawings?

+6
source share
1 answer

Is there a similar approach for drawings?

It should work exactly the same as for layouts.

put png resources in default folder

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

create png s .xml resources

 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 will use png directly

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

Source: https://habr.com/ru/post/914742/


All Articles