Several layouts for tablet and phone

I am developing an Android application for tablet and phone . To do this, I created two folders for the phone ( layout) and one for the tablet’s tablet ( layout-sw600dp).

In accordance with my previous questions, comment I assumed that only tablets will select layouts from layout-sw600dp. But it doesn't seem to work.

For devices nexus 4, nexus 5, nexus 6, nexus 7, a layout is performed layout-sw600dp.

What am I missing here? How to calculate phone / tablet size for correct layouts DP?

Necessary projects for the tablet and phone:

enter image description here

Another retirement for using two separate layouts:

Phone Design:

enter image description here

Tab Design:

enter image description here

answer, , :

  <LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/linearLayouttest">
    <TextView
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_gravity="center_horizontal"
        android:textColor="@color/black"
        android:gravity="left"
        android:text="LabelFirstName"
        android:layout_marginTop="@dimen/_8sdp"
        android:textSize="@dimen/_13sdp"
        android:id="@+id/firstNameLabel"
        android:layout_marginLeft="@dimen/_15sdp"
        android:layout_marginRight="@dimen/_15sdp" />
    <EditText
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:id="@+id/firstName"
        android:layout_marginTop="@dimen/_3sdp"
        android:background="@drawable/edt_bg"
        android:textColor="@color/black"
        android:layout_marginRight="@dimen/_15sdp"
        android:layout_marginLeft="@dimen/_15sdp"
        android:padding="@dimen/_5sdp"
        android:textSize="@dimen/_14sdp"
        android:textColorHint="@color/textColor" />
    <TextView
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_gravity="center_horizontal"
        android:textColor="@color/black"
        android:gravity="left"
        android:text="LabelLastName"
        android:layout_marginTop="@dimen/_3sdp"
        android:textSize="@dimen/_13sdp"
        android:id="@+id/lastNameLabel"
        android:layout_marginLeft="@dimen/_15sdp"
        android:layout_marginRight="@dimen/_15sdp" />
    <EditText
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:id="@+id/lastName"
        android:layout_marginTop="@dimen/_3sdp"
        android:background="@drawable/edt_bg"
        android:textColor="@color/black"
        android:layout_marginRight="@dimen/_15sdp"
        android:layout_marginLeft="@dimen/_15sdp"
        android:padding="@dimen/_5sdp"
        android:textSize="@dimen/_14sdp"
        android:textColorHint="@color/textColor" />
</LinearLayout>

, . ?

+4
2

https://github.com/intuit/sdp , ( ). . , :

<TextView
    android:id="@+id/tv_username"
    android:layout_width="@dimen/_45sdp"
    android:layout_height="@dimen/_45sdp"
    android:text="@string/chat"
    android:textColor="@color/colorPrimary"/>

UPDATE

- , ?

,

public boolean isTablet() {
try {
    // Compute screen size
    DisplayMetrics dm = context.getResources().getDisplayMetrics();
    float screenWidth  = dm.widthPixels / dm.xdpi;
    float screenHeight = dm.heightPixels / dm.ydpi;
    double size = Math.sqrt(Math.pow(screenWidth, 2) + Math.pow(screenHeight, 2));
    // Tablet devices should have a screen size greater than 6 inches
    return size >= 6;

} catch(Exception e) {
    e.printStackTrace();
    return false;
}

}

LinearLayout , :

boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (tabletSize) {
    LinearLayout ll = (LinearLayout) findViewById(R.id.linearLayout);
    ll.setLayoutParams(LinearLayout.WRAP_CONTENT, LinearLayout.WRAP_CONTENT);
    ll.setOrientation(LinearLayout.HORIZONTAL);
} else {
    LinearLayout ll = (LinearLayout) findViewById(R.id.linearLayout);
    ll.setLayoutParams(LinearLayout.WRAP_CONTENT, LinearLayout.WRAP_CONTENT);
    ll.setOrientation(LinearLayout.VERTICAL);
}

XML CORRECTION

:

<LinearLayout
    android:id="@+id/linearLayouttest"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/firstNameLabel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginLeft="@dimen/_15sdp"
            android:layout_marginRight="@dimen/_15sdp"
            android:layout_marginTop="@dimen/_8sdp"
            android:gravity="left"
            android:text="LabelFirstName"
            android:textColor="@color/black"
            android:textSize="@dimen/_13sdp" />

        <EditText
            android:id="@+id/firstName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/_15sdp"
            android:layout_marginRight="@dimen/_15sdp"
            android:layout_marginTop="@dimen/_3sdp"
            android:background="@drawable/edt_bg"
            android:padding="@dimen/_5sdp"
            android:textColor="@color/black"
            android:textColorHint="@color/black"
            android:textSize="@dimen/_14sdp" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/lastNameLabel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginLeft="@dimen/_15sdp"
            android:layout_marginRight="@dimen/_15sdp"
            android:layout_marginTop="@dimen/_3sdp"
            android:gravity="left"
            android:text="LabelLastName"
            android:textColor="@color/black"
            android:textSize="@dimen/_13sdp" />

        <EditText
            android:id="@+id/lastName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/_15sdp"
            android:layout_marginRight="@dimen/_15sdp"
            android:layout_marginTop="@dimen/_3sdp"
            android:background="@drawable/edt_bg"
            android:padding="@dimen/_5sdp"
            android:textColor="@color/black"
            android:textColorHint="@color/black"
            android:textSize="@dimen/_14sdp" />

    </LinearLayout>
</LinearLayout>
+3

xxhdpi xhdpi 5 "- 5" 5 '.

sw600dp

sw600dp-tvdpi

sw720dp

sw720dp-MDPI

sw720dp-xhdpi

. , , . . , .

0

Source: https://habr.com/ru/post/1690660/


All Articles