T. Jony T. Jony - 9 months ago 36
Android Question

Android studios bug or my project is just outdated?

Good evening,

I would appreciate to get a little of help.. :(

I'm trying to support different screen sizes using https://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts webpage.

I have 5 different drawable folders:

drawable(image size 40x48png)

drawable-mdpi(image size 80x96png)

drawable-hdpi(image size 120x144png)

drawable-xhdpi(image size 160x192png)

drawable-xxhdpi(image size 210x252png)

My project includes 5 different layout folders:

layout-sw300dp, 330dp, 480dp, 600dp, 720dp. Every folder has the same layout.xml file.

my layout code:

<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_margin="15dp"
android:text="Truuuuu"
android:textColor="#000000"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.39"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_alignParentStart="true"
android:layout_alignTop="@+id/textView2"
android:layout_marginTop="60dp"
android:background="#ffffff"
android:orientation="horizontal"
android:id="@+id/relativeLayout">

<ImageView
android:id="@+id/off50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:src="@drawable/off50" />

<TextView
android:id="@+id/akcija"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="pewpew!"
android:textSize="20sp"
android:layout_alignTop="@+id/off50"
android:layout_alignParentEnd="true"
android:layout_toEndOf="@+id/off50"
android:textColor="#000000"/>

<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/off50"
android:layout_alignParentEnd="true"
android:text="pewpew"
android:textColor="#000000"
android:textSize="20sp" />



</RelativeLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:layout_alignStart="@+id/relativeLayout"
android:layout_below="@+id/relativeLayout">

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

</RelativeLayout>


My question is.. I do have different image folders and image files right? I made layout folders aswell.


  1. Why the image isn't being scaled on different screen sizes?

  2. Another confusing theory is that, my text isn't scaling either, via layout-sw720dp I can almost read the text. What should I do to support text scaling?



I'm sorry I'm just newbie and this is so confusing for me..

Answer Source

Ok, you're confused.

If you have the same layout file in each sw folder- don't. You only write a new layout file if you have different screen layouts for that size. Note that means entirely new or deleted elements, or changed positions. If you're just changing values, you use values files.

Remember that page you linked, while a good resource, mentions multiple things you can do. You're not supposed to do all of them, in fact some of them are contradictory. The right thing to do depends on how you want things to look.

For your image scaling- you're scaling based on screen density. That means all devices with the same density will use the same drawable, which will make it look the same physical size, but not scale relative tot he size of the device. That may or may not be what you want. If it isn't, you probably want to define a fixed size in dp of the image or make it match_parent and use a scaleType to scale it.

For text size- you're putting a fixed text size of 20sp everywhere. That will make it the same height on all devices. Generally making text bigger on different screen sizes isn't done much. If you want it, make the 20sp a dimension and set different values for it in dimen.xml files based on the size.

Helping you more than this really requires more info- what is it you're trying to achieve and what is it you're getting.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download