0

I want to add some centered elements to a LinearLayout(like textViews or buttons). If I use android:layout_width="fill_parent" the button can be too big on a large screen like a tablet. So I am thinking to limit the width on larger screens.

I use this

      <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical" >

        <LinearLayout android:orientation="vertical"

             android:layout_width="310dp"
             android:layout_height="fill_parent"
             android:paddingBottom ="60dp"
             android:paddingTop ="10dp"
             android:paddingLeft ="5dp"
             android:paddingRight ="5dp"
             android:id="@+id/linear_id"

             >


             ...............


        </LinearLayout>
    </LinearLayout>

From what I see the smallest screen size for Android is 320dp This layout will be displayed ok on any small screen or do you think I could have problems on some devices? I have set the width to 310dp and the total padding is 10dp so in total it should be 320dp.

Thanks

Andrei Ciuca
  • 165
  • 1
  • 3
  • 17
  • did you tried max-width? – Amar Ilindra Oct 26 '16 at 12:32
  • If you want to limit the Button size as half of the screen or some percentage then use weight in your layout. – Kunu Oct 26 '16 at 12:32
  • Thank you for your answers but the layout is looks ok. I am just asking if I could have problems on some phones(where the layout is not displayed properly). I will change the layout only if I could have problems – Andrei Ciuca Oct 26 '16 at 14:49

1 Answers1

0

Replace dp with sdp(scalable dp). This scales with the screen size. It can help you with supporting multiple screens.

Add this dependency in your gradle.

compile 'com.intuit.sdp:sdp-android:1.0.2'

Use like this:- android:paddingLeft ="@dimen/_5sdp"

Also use match_parent instead of fill_parent in LinearLayout's Height/Width

Hope this will help you.... :) :)

Anil_M
  • 10,893
  • 6
  • 47
  • 74
priyanka kataria
  • 417
  • 5
  • 17