'Is there any way to distinguish between if the screen was Small, Normal, Large, or X-Large without creating 4 files?
fragment_categories.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="2"
tools:context=".fragments.CategoriesFragment"
tools:listitem="@layout/row_cateogry" />
I created 4 files of fragment_categories.xml using available qualifiers -> Screen size | Look at UI
- Small ->
app:spanCount="1" - Normal ->
app:spanCount="1" - Large ->
app:spanCount="2" - X-Large ->
app:spanCount="3"
As you noticed I created 4 files of fragment_categories.xml only to change app:spanCount.
Is there any way to distinguish between if the screen was Small, Normal, Large, or X-Large without creating 4 files and without Java, Only in normal XML without available qualifiers?
I can do it in Java in one line to change spanCount, But I have another XML, and more complicated, So it is better to do it in the same XML
I'm using Data Binding Library
Solution 1:[1]
I am using the library I mentioned below to create a responsive structure.
implementation 'com.intuit.sdp:sdp-android:1.0.5'
This library resizes XML automatically. It doesn't matter if the screen is big or small.
you need to sdp the lengths instead of dp. There is a ratio of 3 to 1 here. For example; If it's 100 dp you need to make an image 33sdp.
I may not have fully understood the question. If I misunderstood you can let me know.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | GoldBerg |
