Search code examples
androidandroid-screen

Android Tab - any way to display at phone size?


I have a Samsung Galaxy Tab on which I do development for Android phones. It uses the camera for scanning, so I can't run it on the emulator. Is there any way I can run it on the Tab device, but have it display the same size as a phone? This would be extremely helpful when testing the layouts.


Solution

  • A solution

    You could place your entire layout inside another layout and make your phone layout if you may, have specific pixel dimensions. The gray area is the container which will expand to the dimensions of the tablet, the one with the turtle is your phone screen inside which your layout will reside.

    The code

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#CCCCCC">
    
        <RelativeLayout
            android:id="@+id/your_layout_inside_this"
            android:layout_width="768px"
            android:layout_height="1280px"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:background="#FFFFFF"></RelativeLayout>
    </RelativeLayout>
    

    The preview

    enter image description here

    Considerations

    Don't use this on a production app. I don't think there is a problem with this approach as far as the testing goes and you may have to take into account the density of the tablet compared to the density of the phone you are testing.

    If your testing expands to other things like I may infer from your question, such as taking a picture, you may have to skip using the native intents for taking a picture and use a surfaceview with the dimensions of the phone, but that's a totally different story and question.