Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make android app to fit for all screen sizes

Tags:

android

Well i have activity.xml i which i have a background image and a button which also has a background image in it run well on normal screen but when i run it on xlarge or large screen the position of button changes

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:background="@drawable/menu"
    android:layout_margin="@dimen/my_view_margin"
     >

    <LinearLayout
        android:layout_width="300px"
        android:layout_height="200px"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="172dp"
        android:orientation="vertical" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="60px"
            android:background="@drawable/bt"
            android:text="Button" />
    </LinearLayout>

</RelativeLayout>

this is the code above and below are the images of different screen

cant add images cause doesnt have enough reputation

like image 654
user2624812 Avatar asked Dec 26 '22 23:12

user2624812


2 Answers

Use weight for all layouts instead of giving constant values, Because weight is a type of % for screen.In manifest by default support screen view is true.

and if any times you think, It's not possible than add dimens values {folder contains dimens.xml}

like image 168
sharma_kunal Avatar answered Jan 13 '23 17:01

sharma_kunal


These links will help you to create application for multiple screens :

  1. http://developer.android.com/training/multiscreen/screensizes.html

  2. http://developer.android.com/guide/practices/screens_support.html

These are android's official documents on implementing support for multiple screen sizes.

like image 23
Vipul Purohit Avatar answered Jan 13 '23 17:01

Vipul Purohit