2

A problem that has been nagging me for weeks now, tried everything but to no avail.

What I want to do is have the EXACT SAME layout on EVERY screen size. Let me illustrate by using a picture:

On a 2.7 inch device: 2.7inch

On a 10.1 inch device (badly photoshopped image for illustration purposes): 10.1inchdesired

But with the current Android implementation, i get this on 10.1 inch devices: 10.1inch

In short, i want my application to look the same (relatively speaking) including button sizes, text scaling etc etc on all screen sizes. I did this before by overriding View class, making my own View and drawing everything inside, but with that method, adding view elements got unwieldly verry verry fast and the advantages of having an "onClick" callback functionality was also gone (since i just programatically drew bitmaps inside the overriden View class to function as buttons). Is there any way to achieve this using the android xml files?

Here is my (test) XML code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:gravity="center">

    <Button
        android:id="@+id/button_1"
        android:layout_height="fill_parent"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:text="ABCDEF" />
    <Button
        android:id="@+id/button_2"
        android:layout_height="fill_parent"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:text="GHI" />
    <Button
        android:id="@+id/button_3"
        android:layout_height="fill_parent"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:text="JKLM" />
</LinearLayout>
Maarten
  • 309
  • 5
  • 14
  • You can change the text size and its scaling programmatically by detecting the screen size/resolution ? – SALMAN Jul 24 '12 at 20:16
  • Apparently using the weights is the way to go : https://stackoverflow.com/a/27042447/6165833 (and using the new ContraintLayout : https://developer.android.com/training/constraint-layout/index.html#constrain-chain) – ymoreau Oct 23 '19 at 19:16

0 Answers0