0

In my app i have created a layout which works well on my device as i use small font and display size small but my clients uses big font and big display size, so the layout breaks.

My code - https://del.dog/ciletamaye.htm

How to make layouts that work well in such diverse device screens

enter image description here

enter image description here

Shubham Gajra
  • 69
  • 1
  • 7

2 Answers2

0

Use below attribute on textview

<TextView
      android:maxLines="1"
     .../>

And consider using RecyclerView instead of adding each CardView one by one.

SABANTO
  • 1,316
  • 9
  • 24
-1

This will adjust to a specific phone screen size.

An Android SDK that provides a new size unit - sdp (scalable dp). This size unit scales with the screen size.

Use this for DP values: https://github.com/intuit/sdp

Example usage:

<LinearLayout
android:id="@+id/give_us_a_review_landmine_main_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="@dimen/_27sdp"
android:paddingLeft="@dimen/_43sdp"
android:paddingRight="@dimen/_43sdp"
android:paddingTop="@dimen/_50sdp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Intuit"
android:textColor="@android:color/black"
android:textSize="@dimen/_40sdp"/>

For more accuracy, follow this code and create a new layout with the same name as the one you want to recreate and add smallest-width as a parameter when you create a new layout and enter in the smallest width the WIDTH value you get from this code on the phone you want to create a perfect layout for (many screens have different sizes hence why you need to account for them and adjust accordingly):

void printSecreenInfo(){

    Display display = getWindowManager().getDefaultDisplay();
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);

    Log.i(TAG, "density :" +  metrics.density);

    // density interms of dpi
    Log.i(TAG, "D density :" +  metrics.densityDpi);

    // horizontal pixel resolution
    Log.i(TAG, "width pix :" +  metrics.widthPixels);

     // actual horizontal dpi
    Log.i(TAG, "xdpi :" +  metrics.xdpi);

    // actual vertical dpi
    Log.i(TAG, "ydpi :" +  metrics.ydpi);

}

(https://stackoverflow.com/a/13802113/9842400)

And in similar fashion, to test the given device on an emulator, find out the exact dimensions of the phone screen you want to create for, 1080 x 720 for example and create an emulator with those dimensions. Then you can see how it will look on the device you are aiming to create for.

Treewallie
  • 346
  • 2
  • 13