-1

I need my app shows a white rectangle from below by clicking a button. Is there a way to set its size and padding automatically, so it can fill perfectly on all type of devices? This is my XML code, that permits a rectangle to slide from below:

XML:

<ImageView 
  android:id="@+id/viewtab"
  android:layout_width="359dp"    <!-- I'd like it autosized with padding-->
  android:layout_height="75dp" /> <!-- I'd like it autosized with padding-->

Java:

Vtab = (ImageView) findViewById(R.id.viewtab);
Vtab.setVisibility(VISIBLE);

2 Answers2

1

Yes you can add one library like

add below dependency into app level gradle file ..

implementation 'com.intuit.sdp:sdp-android:1.0.4'

then after give size like below code ..

    <ImageView
    android:id="@+id/viewtab"
    android:layout_width="@dimen/_359sdp"
android:layout_height="@dimen/_75sdp" />

then same size all device.

1

Shortcut:

May be you can try below library which manages all the screen size resolution automatically.

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

You need to just add the dependency in your build.gradle file and you are done.

You need to specify like:

android:layout_height="@dimen/_10sdp"

Instead of:

android:layout_height="@dimen/10sdp"

Second way:

Using Android PercentRelativeLayout like

<android.support.percent.PercentRelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/viewtab"
        android:layout_width="80%"
        android:layout_width="0dp"
        android:layout_height="50%"
        android:layout_height="0dp"/>

</android.support.percent.PercentRelative

Third long way:

You have to create Different values folder for different screens . Like

values-sw720dp          10.1” tablet 1280x800 mdpi

values-sw600dp          7.0”  tablet 1024x600 mdpi

values-sw480dp          5.4”  480x854 mdpi 
values-sw480dp          5.1”  480x800 mdpi 

values-xxhdpi           5.5"  1080x1920 xxhdpi
values-xxxhdpi           5.5" 1440x2560 xxxhdpi

values-xhdpi            4.7”   1280x720 xhdpi 
values-xhdpi            4.65”  720x1280 xhdpi 

values-hdpi             4.0” 480x800 hdpi
values-hdpi             3.7” 480x854 hdpi

values-mdpi             3.2” 320x480 mdpi

values-ldpi             3.4” 240x432 ldpi
values-ldpi             3.3” 240x400 ldpi
values-ldpi             2.7” 240x320 ldpi

enter image description here

For more information you may visit here

Different values folders in android

http://android-developers.blogspot.in/2011/07/new-tools-for-managing-screen-sizes.html

Plugin to auto generate dimens

You can make use of Android Studio plugin called Dimenify to auto generate dimension values for other pixel buckets based on custom scale factors. Its still in beta, be sure to notify any issues/suggestions you come across to the developer.

Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212