0

I have a design to place the buttons in a shape of similar to quarter part of ellipse. I tried with Linear layout and relative layout. Not fixed with both. How should I fix this for multiple screens(Tablet with Landscape). Code of that layout added below..

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/mainscreen_bg"
android:layout_gravity="center_horizontal">

<!--LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal" >

<Button
    android:id="@+id/button1"
    android:layout_width="75dp"
    android:layout_height="wrap_content"
    android:text="LogIn/SignUp" /-->

<Button
    android:id="@+id/rate"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_marginRight="20dp"
    android:layout_alignParentBottom="true"
    android:background="@drawable/rate" />

<Button
    android:id="@+id/vehicle"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_marginRight="20dp"
    android:layout_toRightOf="@id/rate"
    android:layout_above="@id/rate"
    android:background="@drawable/vehicle" />

<Button
    android:id="@+id/hotel"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_marginRight="20dp"
    android:layout_toRightOf="@id/vehicle"
    android:layout_above="@id/vehicle"
    android:background="@drawable/hotel" />

<Button
    android:id="@+id/user"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_marginRight="20dp"
    android:layout_toRightOf="@id/hotel"
    android:layout_above="@id/hotel"
    android:background="@drawable/newcustomer" />

<Button
    android:id="@+id/return_vehicle"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_marginRight="20dp"
    android:layout_toRightOf="@id/user"
    android:layout_above="@id/user"
    android:background="@drawable/return1" />

<Button
    android:id="@+id/sync"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_marginRight="20dp"
    android:layout_toRightOf="@id/return_vehicle"
    android:layout_above="@id/return_vehicle"
    android:background="@drawable/sync" />

<Button
    android:id="@+id/report"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_toRightOf="@id/sync"
    android:layout_above="@id/sync"
    android:background="@drawable/report" />

<Button
    android:id="@+id/settings"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    android:background="@drawable/password_reset" />
<!-- /LinearLayout-->

</RelativeLayout>

enter image description here

Abish R
  • 1,537
  • 3
  • 18
  • 36
  • 1
    you set ``android:layout_width="80dp"`` for all button, but the width of screen not enough to display. So, i suggest you use ``LinearLayout`` and set ``android:layout_width="0dp"`` and ``android:layout_weight="1"`` for all button – Danh DC Jan 20 '16 at 06:37
  • +1 what @DanhDC says, just keep in mind that if you do that and you have text in your buttons, you might have problems showing them properly. – Apostrofix Jan 20 '16 at 06:39
  • Thanks both. But my problem is displaying buttons in arc. I set property means it will set and fit the all buttons in screen. That is good. But how to set those buttons in arc(Little similar to quarter part of ellipse). – Abish R Jan 20 '16 at 06:53

2 Answers2

0

Android is smart enough to distinguish between two same layout files of different screen size. To define layout for different screen size,goto Layout>Available qualifiers>size and press >> arrow and choose your required screen size.Inside the choosen layout, modify the views dimension according to the requirement. Note: Layout file name for small screen and large screen must be same. And Android will choose the required file at runtime

If your looking for brief explanation, read this.

Community
  • 1
  • 1
ishwor kafley
  • 938
  • 14
  • 32
  • Thanks ishwor. I have the problem of placing buttons in the arc. If I drag and drop the buttons in relative layout means it won't work in other screens. – Abish R Jan 20 '16 at 06:59
0

You can also give multiple screen support by dimen.xml file

for example if you want same textsize will be appear same in all devices than you can create dimen.xml and store dimension by using

dimen.xml
<dimen name="textsize">18sp</dimen>

dimen.xml(sw600dp)
<dimen name="textsize">20sp</dimen>


dimen.xml(sw720dp)
<dimen name="textsize">22sp</dimen>


dimen.xml(sw820dp)
<dimen name="textsize">24sp</dimen>

And Apply to textview size in example.xml

 <TextView
            android:id="@+id/tv_dialog_birthdate"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="@dimen/textsize" />