There is a slight difference between the activity design screen in the android studio and the AVD or physical device.

Asked 2 years ago, Updated 2 years ago, 24 views

Hello, there is a slight difference between the activity design screen in Android Studio and the AVD or actual device screen.

In the activity design screen of Android Studio, the part with numbers is located in the middle of the division symbol as shown in the picture below. (To delete the title bar, it is viewed as API 19 screen.))

In AVD, you can see that the numbers are down a little bit.

It's another AVD, which is also slightly different from the activity design screen of Android Studio.

The same goes for real devices. Is the activity design screen 100% unreliable because it is so different from the activity design screen? How much sense should I code for these subtle differences?

android

2022-09-22 11:34

2 Answers

In the Android studio, select the layout preview settings the same as the actual device. It's hard to feel the difference between preview and actual device in my Nexus 6P (although I might lose my touch)

Personally, I use the preview to check the layout's configuration, location, and whether there are any mistakes, and I tend to check the final design on the device.


2022-09-22 11:34

As you can see from the Component Tree, the FrameLayout divided image is placed underneath and the numbers are in Linearlayout above it. It looks like a picture in the design window of Android Studio, but in the actual device, or on the AVD screen, the Linear Layout with numbers is pushed down slightly and output.

I solved the problem by giving a margin with my gut. I'm leaving more specific information in case experts know the cause.

The source code of the corresponding fragment. You can see that RelativeLayout and LinearLayout are on top of FrameLayout.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="37dp"
            android:src="@drawable/div_sign_long"
            android:layout_centerHorizontal="true"
            android:id="@+id/div_sign" />

    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/quotient"
    ...

The source code for Activity to contain the above fragments. The location where the Frament enters is a FrameLayout called fragment_container.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="wrap_content">
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:id="@+id/main_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="10dp"
        android:background="#ffffff">

        <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true" />

        <fragment
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/numberPadFragment"
    ...

Margin, padding, and other attributes of View may cause such a phenomenon... I'm really curious if it's like that, but I can't find a definite answer.


2022-09-22 11:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.