0

I have two tablets. I have run a test resolution app to get screen parameters. Thouse are the results.

1) Coby MID7042 7": low density, scale: 0.75, 120dpi, 480 x 764, layout for large screen, drawable LDPI.

2) BQ Elcano 7": high density, scale: 1.5, 240dpi, 800 x 1208, layout for large screen, drawable HDPI.

I have developed an android application that fits good on Coby screen, but in BQ the screen is cut in the right and in the bottom. That is, the screen is bigger than you can see on the screen. I think BQ screen is better and bigger than Coby, but I don't know why it doesn't fit the screen.
In my developed android app, the xml file for the screen is into res/layout folder. I always use sp and dp.
I have read about "supporting multiple screen" and so on, but in this case, I think BQ should show the screen at right fit using the same layout. But it doesn't.
Some one could help me about this issue? I don't know how could I solve this, because two tablets are large for layouts.
Thanks.
Edited. This is a layout that is cut in the right (the latest EditText is cut):

    <LinearLayout
style="@style/GroupBox3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:baselineAligned="true" >
<LinearLayout
    android:layout_width="130dp"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
    <TextView
    android:id="@+id/TextView08"
    style="@style/etstyle1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:text="@string/Box" />
    <EditText
    android:id="@+id/eBox"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="6dp"
    android:layout_weight="1"
    android:background="@drawable/roundedittext"
    android:ems="10"
    android:enabled="true"
    android:gravity="right"
    android:inputType="number|numberSigned|numberDecimal"
    android:selectAllOnFocus="true" >
    </EditText>
</LinearLayout>
<LinearLayout
    android:layout_width="130dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:orientation="vertical" >
    <TextView
    android:id="@+id/TextView06"
    style="@style/etstyle1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:text="@string/Uds" />
    <EditText
    android:id="@+id/euds"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="6dp"
    android:background="@drawable/roundedittext"
    android:ems="10"
    android:enabled="true"
    android:gravity="right"
    android:inputType="number|numberSigned|numberDecimal"
    android:selectAllOnFocus="true" />
</LinearLayout>
<LinearLayout
    android:layout_width="130dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:orientation="vertical" >
    <TextView
    android:id="@+id/TextView09"
    style="@style/etstyle1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal|left"
    android:paddingLeft="10dp"
    android:text="@string/Tar" />
    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:paddingBottom="5dp" >
    <EditText
        android:id="@+id/etar"
        android:layout_width="60dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:background="@drawable/roundedittext"
        android:ems="10"
        android:enabled="true"
        android:gravity="center_vertical|right"
        android:inputType="number"
        android:selectAllOnFocus="true" />
    <Button
        android:id="@+id/btnTarifa"
        style="@style/btnSer"
        android:layout_width="50dp"
        android:layout_height="40dp"
        android:layout_gravity="center_vertical|center_horizontal|center"
        android:layout_marginTop="2dp"
        android:text="@string/Inter" />
    </LinearLayout>
</LinearLayout>
<LinearLayout
    android:layout_width="135dp"
    android:layout_height="match_parent"
    android:layout_marginLeft="5dp"
    android:orientation="vertical" >
    <TextView
    android:id="@+id/etit"
    style="@style/etstyle1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:text="@string/price" />
    <EditText
    android:id="@+id/eprice"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="6dp"
    android:background="@drawable/roundedittext"
    android:ems="10"
    android:enabled="true"
    android:gravity="center_vertical|right"
    android:inputType="numberDecimal"
    android:selectAllOnFocus="true" />
</LinearLayout>
</LinearLayout>
briast
  • 286
  • 4
  • 19

4 Answers4

2

DroidUsers answer is little bit confusing but method is effective... look for more effective example: http://www.vanteon.com/downloads/Scaling_Android_Apps_White_Paper.pdf

Ameen
  • 41
  • 5
  • I have referenced the same but lost the document and link, thats why i had to give my own code as sample... – Fahad Jun 16 '14 at 09:22
0

I have Used one approach where I design the Layout I wanted in a standard device, and store all dynamically apply all the layout dependent values(eg: padding, margin etc) using a seperate class. And by calculating a ratio with current device config to the standard i have stored,

I will give you my sample code. just go through it and find your way accordingly

public class ListViewDimensions 
{
    private Context _context;
    private Configuration config;
    private Display display;
    private int _width;
    private int _height;
    private int _portOrLand;
    private int _ORIENTATION_LAND=2;
    private int _ORIENTATION_PORT=1;
    private DisplayMetrics metrics;
    private Dimension dimension;


//***************************** PORTRAIT ********************************\\

            public int PlistLayoutPaddingLeft=16;
            public int PlistLayoutPaddingRight=16;  
            public int PlistLayoutPaddingTop=16;
            public int PlistLayoutPaddingBottom=15;

            public int PsuraNoTextsize=10;
            public int PsuraNameTextsize=20;
            public int PayaNoTextsize=10;
            public int PsuraNameWidth=180;  

            public int PpageNoTextsize=10;
            public int PpageNoPadding=2;   

            public int PmalayalamFontsize;
            public int ParabiFontsize;

            public int PsuraHeadHeight=40;

//----------------------------------------------------------------------------------------




//***************************** LANDSCAPE IN TABS ********************************\\




            public int LTlistLayoutPaddingLeft=35;
            public int LTlistLayoutPaddingTop=30;
            public int LTlistLayoutPaddingRight=35;         
            public int LTlistLayoutPaddingRightRightPage=35;            
            public int LTlistLayoutPaddingBottom=5;


            public int LTpageNoTextsize=13;
            public int LTpageNoPadding=0;   

            public int LTsuraNoTextsize=15;
            public int LTsuraNameTextsize=25;
            public int LTayaNoTextsize=15;
            public int LTsuraNameWidth=375;  


            public int LTmalayalamFontsize;
            public int LTarabiFontsize;

            public int LTsuraHeadHeight=60;

//----------------------------------------------------------------------------------------




//***************************** LANDSCAPE IN NON-TABS ********************************\\

            public int LlistLayoutPaddingLeft=21;
            public int LlistLayoutPaddingRight=20;  
            public int LlistLayoutPaddingTop=16;
            public int LlistLayoutPaddingBottom=17;

            public int LsuraNoTextsize=10;
            public int LsuraNameTextsize=20;
            public int LayaNoTextsize=10;
            public int LsuraNameWidth=330;  

            public int LpageNoTextsize=13;
            public int LpageNoPadding=3;   

            public int LmalayalamFontsize;
            public int LarabiFontsize;

            public int LsuraHeadHeight=40;

//----------------------------------------------------------------------------------------

            public float xScale;
            private float yScale;
            private double diagonalInches;


public class Dimension
{

    public int listLayoutPaddingLeft;
    public int listLayoutPaddingRight;  
    public int listLayoutPaddingTop;
    public int listLayoutPaddingBottom;

    public int pageNoTextsize;
    public int pageNoPadding;   

    public int suraNoTextsize;
    public int suraNameTextsize;
    public int ayaNoTextsize;
    public int suraNameWidth;  

    public int malayalamFontsize;
    public int arabiFontsize;
    public int suraHeadHeight;
    public String bismi;

}

public ListViewDimensions.Dimension getDimensions(Context c)
{

     PmalayalamFontsize=MyApp.appSettings.listMalayalamFontSize;
     ParabiFontsize=MyApp.appSettings.listMalayalamFontSize;

     LTmalayalamFontsize=MyApp.appSettings.listMalayalamFontSize*2;
     LTarabiFontsize=MyApp.appSettings.listMalayalamFontSize*2;

     LmalayalamFontsize=MyApp.appSettings.listMalayalamFontSize;
     LarabiFontsize=MyApp.appSettings.listMalayalamFontSize;


    dimension=new Dimension();

    _context=c;
    config =c.getResources().getConfiguration();
    display=((Activity) c).getWindowManager().getDefaultDisplay(); 


    _width = display.getWidth();
    _height =display.getHeight();

    if(config.orientation==config.ORIENTATION_LANDSCAPE)
        _portOrLand=_ORIENTATION_LAND;
    else 
        _portOrLand=_ORIENTATION_PORT;

    metrics = new DisplayMetrics(); 
    ((Activity) c).getWindowManager().getDefaultDisplay().getMetrics(metrics);

    int widthPixels = metrics.widthPixels;
    int heightPixels = metrics.heightPixels;    
    int density=metrics.densityDpi;
    float widthDpi = metrics.xdpi;
    float heightDpi = metrics.ydpi;

    if(density/widthDpi>1.2)
    {
        widthDpi=density;
        heightDpi=density;
    }

    float widthInches = widthPixels / widthDpi;
    float heightInches = heightPixels / heightDpi;  
    diagonalInches = Math.sqrt((widthInches * widthInches) + (heightInches * heightInches));

    if(diagonalInches>=6.7 && _portOrLand==_ORIENTATION_LAND)
    {
        //TODO :   for landscape in tabs
        xScale =  (_width/2)/(float)640 ;            
        yScale = _height/(float)752 ; 



        dimension.listLayoutPaddingLeft=LTlistLayoutPaddingLeft;
        dimension.listLayoutPaddingRight=LTlistLayoutPaddingRight;  
        dimension.listLayoutPaddingTop=LTlistLayoutPaddingTop;
        dimension.listLayoutPaddingBottom=LTlistLayoutPaddingBottom;

        dimension.pageNoTextsize=LTpageNoTextsize;
        dimension.pageNoPadding=LTpageNoPadding;  

        dimension.malayalamFontsize=LTmalayalamFontsize;
        dimension.arabiFontsize=LTarabiFontsize;

        dimension.suraNoTextsize=LTsuraNoTextsize;
        dimension.suraNameTextsize=LTsuraNameTextsize;
        dimension.ayaNoTextsize=LTayaNoTextsize;
        dimension.suraNameWidth=LTsuraNameWidth;   
        dimension.suraHeadHeight=LTsuraHeadHeight;
        dimension.bismi="&%$";
    }
    else if( _portOrLand==_ORIENTATION_PORT)
    {
        //TODO :   for portrait in non-tab devices and tabs
        xScale =  _width/(float)320 ;
        yScale = _height/(float)480 ;



        dimension.listLayoutPaddingLeft=PlistLayoutPaddingLeft;
        dimension.listLayoutPaddingRight=PlistLayoutPaddingRight;   
        dimension.listLayoutPaddingTop=PlistLayoutPaddingTop;
        dimension.listLayoutPaddingBottom=PlistLayoutPaddingBottom;

        dimension.pageNoTextsize=PpageNoTextsize;
        dimension.pageNoPadding=PpageNoPadding;   //TODO: check whether it is mandatory

        dimension.malayalamFontsize=PmalayalamFontsize;
        dimension.arabiFontsize=ParabiFontsize;

        dimension.suraHeadHeight=PsuraHeadHeight;

        dimension.suraNoTextsize=PsuraNoTextsize;
        dimension.suraNameTextsize=PsuraNameTextsize;
        dimension.ayaNoTextsize=PayaNoTextsize;
        dimension.suraNameWidth=PsuraNameWidth;  

        if(diagonalInches<4.0)
            dimension.bismi="ó";
        else
            dimension.bismi="&%$";

    }
    else if(diagonalInches<6.7 && _portOrLand==_ORIENTATION_LAND)
    {
        //TODO :   for land in non-tab devices 
        xScale =  _height/(float)320 ;
        yScale = _width/(float)480 ; 

        dimension.listLayoutPaddingLeft=LlistLayoutPaddingLeft;
        dimension.listLayoutPaddingRight=LlistLayoutPaddingRight;   
        dimension.listLayoutPaddingTop=LlistLayoutPaddingTop;
        dimension.listLayoutPaddingBottom=LlistLayoutPaddingBottom;

        dimension.suraHeadHeight=LsuraHeadHeight;           
        dimension.suraNoTextsize=LsuraNoTextsize;
        dimension.suraNameTextsize=LsuraNameTextsize;
        dimension.ayaNoTextsize=LayaNoTextsize;
        dimension.suraNameWidth=LsuraNameWidth;  

        dimension.pageNoTextsize=LpageNoTextsize;
        dimension.pageNoPadding=LpageNoPadding;   //TODO: check whether it is mandatory

        dimension.malayalamFontsize=LmalayalamFontsize;
        dimension.arabiFontsize=LarabiFontsize;
        dimension.suraHeadHeight=LsuraHeadHeight;   
        dimension.bismi="&%$";

    }


    dimension.listLayoutPaddingLeft=(int) (dimension.listLayoutPaddingLeft*xScale);
    dimension.listLayoutPaddingRight=(int) (dimension.listLayoutPaddingRight*xScale);
    dimension.listLayoutPaddingTop=(int) (dimension.listLayoutPaddingTop*yScale);
    dimension.listLayoutPaddingBottom=(int) (dimension.listLayoutPaddingBottom*yScale);

    dimension.pageNoTextsize=(int) (dimension.pageNoTextsize*xScale);
    dimension.pageNoPadding=(int) (dimension.pageNoPadding*yScale); 

    dimension.malayalamFontsize=(int) (dimension.malayalamFontsize*xScale);
    dimension.arabiFontsize=(int) (dimension.arabiFontsize*xScale);
    dimension.suraHeadHeight=(int) (dimension.suraHeadHeight*yScale);



dimension.suraNoTextsize=(int) (dimension.suraNoTextsize*xScale);
        dimension.suraNameTextsize=(int) (dimension.suraNameTextsize*xScale);
        dimension.ayaNoTextsize=(int) (dimension.ayaNoTextsize*xScale);
        dimension.suraNameWidth=(int) (dimension.suraNameWidth*xScale);  




    return this.dimension;

}

public ListViewDimensions.Dimension updateFontSize() 
{
    if(diagonalInches>=6.7 && _portOrLand==_ORIENTATION_LAND)
    {

        xScale =  (_width/2)/(float)640 ;            
        yScale = _height/(float)752 ; 

        dimension.malayalamFontsize=LTmalayalamFontsize;
        dimension.arabiFontsize=LTarabiFontsize;
    }
    else if( _portOrLand==_ORIENTATION_PORT)
    {


        xScale =  _width/(float)320 ;
        yScale = _height/(float)480 ;

        dimension.malayalamFontsize=PmalayalamFontsize;
        dimension.arabiFontsize=ParabiFontsize;
    }
    else if(diagonalInches<6.7 && _portOrLand==_ORIENTATION_LAND)
    {
        xScale =  _height/(float)320 ;
        yScale = _width/(float)480 ; 

        dimension.malayalamFontsize=LmalayalamFontsize;
        dimension.arabiFontsize=LarabiFontsize;
    }
    dimension.malayalamFontsize=(int) (dimension.malayalamFontsize*xScale);
    dimension.arabiFontsize=(int) (dimension.arabiFontsize*xScale);

    return dimension;
}


}
Fahad
  • 193
  • 1
  • 9
  • It's not good idea to do so. There is better way to achieve what you doing with xml files. It's very flexible tools to make layouts for various screen. read this http://developer.android.com/guide/practices/screens_support.html – Alexander Mikhaylov May 07 '14 at 09:22
  • I know,its not the actual way. what that link provided didn't fully worked with my app, so I just had to do this way. Anyway it worked for me – Fahad May 07 '14 at 09:26
  • I think, you need read a little bit more about it. Your solution using dimension in pixels - it's very bad. Your solution may work, but other developers can't support your code. Find a time to make it better (with xmls, with different values folders and different layout folders). – Alexander Mikhaylov May 07 '14 at 09:29
  • That was a special case project, and I am done with that,although I think use of pixel is the right way when we manage density and scales ourselves – Fahad May 07 '14 at 09:35
  • You don't need to manage density, I think. There are very powerful tool for that in android sdk. I think, that developers in android team do it really good. I don't like code with such which reinvent the wheel, because it's really unsupportable – Alexander Mikhaylov May 07 '14 at 09:56
  • if its helpful to others than the documented screen_support whose having situation like me, (this question also contains "I have read about "supporting multiple screen" and so on, but in this case, I think BQ should show the screen at right fit using the same layout. But it doesn't.")why you are against it? – Fahad May 07 '14 at 10:08
0

You should try to work with android:layout_weight instead of specifying your LinearLayout's android:layout_width="130dp". This way, the widths of your textviews and edittexts and what not can be set to fill_parent and Android will scale anything to the size of your screen, whatever the device you're working on might be.

With an exception for the linear layout where you have a new linearlayout for the edittext and a button, there you should use the weight attribute for this edittext and button again instead of their width parameters.

A slightly modified (I couldn't keep the style and text attributes when testing, for obvious reasons) example of how your xml would look:

<LinearLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_marginTop="5dp"
  android:layout_weight="1"
  android:baselineAligned="true" >

    <LinearLayout
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:layout_weight="1" >

        <TextView
          android:id="@+id/TextView08"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" />
        <EditText
          android:id="@+id/eBox"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="6dp"
          android:ems="10"
          android:enabled="true"
          android:gravity="right"
          android:inputType="number|numberSigned|numberDecimal"
          android:selectAllOnFocus="true" >
        </EditText>
    </LinearLayout>
    <LinearLayout
      android:layout_height="wrap_content"
      android:layout_marginLeft="10dp"
      android:orientation="vertical"
      android:layout_weight="1" >

        <TextView
          android:id="@+id/TextView06"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:gravity="center_horizontal" />
        <EditText
          android:id="@+id/euds"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="6dp"
          android:ems="10"
          android:enabled="true"
          android:gravity="right"
          android:inputType="number|numberSigned|numberDecimal"
          android:selectAllOnFocus="true" />
    </LinearLayout>
    <LinearLayout
      android:layout_height="wrap_content"
      android:layout_marginLeft="10dp"
      android:orientation="vertical"
      android:layout_weight="1" >
        <TextView
          android:id="@+id/TextView09"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:gravity="center_horizontal|left"
          android:paddingLeft="10dp" />
        <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:gravity="center_horizontal"
          android:paddingBottom="5dp" >
            <EditText
              android:id="@+id/etar"
              android:layout_weight="0.5"
              android:layout_height="wrap_content"
              android:layout_marginTop="5dp"
              android:ems="10"
              android:enabled="true"
              android:gravity="center_vertical|right"
              android:inputType="number"
              android:selectAllOnFocus="true" />
            <Button
              android:id="@+id/btnTarifa"
              android:layout_weight="0.5"
              android:layout_height="40dp"
              android:layout_gravity="center_vertical|center_horizontal|center"
              android:layout_marginTop="2dp" />
        </LinearLayout>
    </LinearLayout>
    <LinearLayout
      android:layout_weight="1"
      android:layout_height="match_parent"
      android:layout_marginLeft="5dp"
      android:orientation="vertical" >
        <TextView
          android:id="@+id/etit"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:gravity="center_horizontal" />
        <EditText
          android:id="@+id/eprice"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="6dp"
          android:ems="10"
          android:enabled="true"
          android:gravity="center_vertical|right"
          android:inputType="numberDecimal"
          android:selectAllOnFocus="true" />
     </LinearLayout>
</LinearLayout>
SvenT23
  • 667
  • 6
  • 19
  • Thanks for your answer. Yes, I know I should use weight better than width, but It has a problem (from my point of view) that the edittext grow without limit, and some field looks very ugly. It will be perfect for me if I could set a max-width paramater with weigth, but there isn't. Anyway, my question is why it doesn't fit in a better screen (with more resolution and dpi). If you can see the whole screen on the Coby, I think I could see on the BQ very well. – briast May 07 '14 at 11:40
  • Sadly I'm not sure either about why this could be happening and I don't have the devices to test this, so I'm afraid I can't help you with discovering why that seems to be happening. – SvenT23 May 07 '14 at 11:47
0

After lot of sarch I haven't found why it happens, but a very quickly solution. I can scale all the application adding this code to the main activity:

public void changeDensity(float desiredDensity) {
//desiredDensity : ldpi = 0.75 (120dpi) , mdpi = 1 (160dpi), hdpi = 1.5 (240dpi), xhdpi = 2.0 (320dpi)
DisplayMetrics metrics = getResources().getDisplayMetrics();

metrics.density = desiredDensity;
metrics.xdpi = desiredDensity * 160;
metrics.ydpi = desiredDensity * 160;
metrics.densityDpi = (int) (desiredDensity * 160);

getResources().updateConfiguration(null, null);

}

Calling this function on creating main activity, with 1.25f as desiredDensity, the application is scaled to fit the right dimension. I know this isn't the rigth way. I should change all layout, but I can't do it with this device because both use the same layout (large) and then, perhaps, I should use w as parameter in res/layout. Briefly, scaling resolve the problem.
From this: https://stackoverflow.com/a/12077236/1616700

Community
  • 1
  • 1
briast
  • 286
  • 4
  • 19