user6534005
user6534005

Reputation:

Design looks perfect on phone but so small on tablet - android studio

I made up this xml file for my android project, the design looks perfect on my phone but running it on my tablet makes buttons, images,... look so small, i would love to make their size change according to the device running on.

here's my xml file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    android:fitsSystemWindows="true"
    tools:context="molfix.dev.molfix.Activities.Bvn.BienvenuActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:background="#91d0f0"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:background="@drawable/toolbar_bvn"
            android:scrollbars="none"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            android:weightSum="1">
        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <Button
        android:layout_width="250dp"
        android:layout_height="55dp"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:background="@drawable/button_inscrip"
        android:id="@+id/b_inscrip"
        android:layout_marginTop="20dp"
        android:layout_below="@+id/b_connex"
        android:layout_centerHorizontal="true" />

    <Button
        android:layout_width="250dp"
        android:layout_height="55dp"
        android:background="@drawable/button_connex"
        android:id="@+id/b_connex"
        android:layout_marginTop="151dp"
        android:layout_below="@+id/appbar"
        android:layout_alignStart="@+id/b_inscrip" />
</RelativeLayout>

Upvotes: 2

Views: 799

Answers (2)

priyanka kataria
priyanka kataria

Reputation: 417

You can try scalable dp instead of dp/sp etc. This will adjust the size of views according to device running on.

Dependency:-

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

Use like this:-

Replace all "10dp" (your dp value) with "dimen/_10sdp" (change according to your dp value) in your xml.

Upvotes: 2

MinnuKaAnae
MinnuKaAnae

Reputation: 1646

You have to design your xmls for multi screens. For tab supported, you should create layout-sw600dp layout, this will support 7 inch tablets and for 10 inch tablet create layout-sw720dp. After creating those layouts in res folder copy and paste your xmls in that folders and give sizes for views according to your requirement.

Upvotes: 0

Related Questions