1

i'm new to the android when i'm creating the button it's become variation in different mobiles please help me.

<LinearLayout android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="center_horizontal">
        <Button
            android:layout_width="wrap_content"
            android:gravity="center"
            android:width="300sp"
            android:layout_height="wrap_content"
            android:text="chennai to coimbatore"/>
    </RelativeLayout>
</LinearLayout>
just_user
  • 11,769
  • 19
  • 90
  • 135
chandra
  • 229
  • 1
  • 2
  • 8

4 Answers4

0

You are using the sp unit which is device independent BUT is scaled with the user's font size preference

Just use dp instead

devnull69
  • 16,402
  • 8
  • 50
  • 61
0

different mobile have a different density so that you button like small medium as per density

Divyesh Boda
  • 258
  • 2
  • 12
0

construct your button like below. Remove android:width="300sp", It is not needed:

<LinearLayout android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_gravity="center_horizontal">
        <Button         
          android:layout_width="300dp"
          android:gravity="center"
          android:layout_height="wrap_content"
          android:text="chennai to coimbatore"/>
    </RelativeLayout>
</LinearLayout>
Janki Gadhiya
  • 4,492
  • 2
  • 29
  • 59
  • then also i'm getting that Problem only i used DP instated of SP then also it is variations haveing – chandra Jun 16 '16 at 11:41
  • If you implemented the same as i have done above you will not have that problem..!! check it once i have updated with full code.. Just copy-paste it and see what happens..!! – Janki Gadhiya Jun 16 '16 at 11:55
0

Use dp instead of sp. As per documentation (https://developer.android.com/guide/practices/screens_support.html) "you should prefer the sp (scale-independent pixel) to define text sizes. The sp scale factor depends on a user setting and the system scales "

Renu Yadav
  • 316
  • 1
  • 6