简体   繁体   中英

Android studio design preview differs from runtime layout

I layed out an xml file like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="16dp"
    android:paddingBottom="16dp"
    tools:context=".MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:background="@android:color/holo_red_dark"
        android:paddingLeft="8dp"
        android:paddingRight="8dp">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingTop="8dp"
            android:paddingBottom="8dp">

            <TextView
                android:textAppearance="@android:style/TextAppearance.Large"
                android:id="@+id/price_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="50 234 qwerty."/>

            <TextView
                android:id="@+id/discount_text"
                android:layout_width="wrap_content"
                android:textAppearance="@android:style/TextAppearance.Small"
                android:layout_height="wrap_content"
                android:text="qwerty 12 3456."/>

        </LinearLayout>

    </RelativeLayout>

</RelativeLayout>

But the results that appear when app is running differ from the preview window. Particularly the bottom text seems to be cut off. I have the same theme setup in both the app and preview window, I use the same device. Text size on the device is normal. Still it differs - why?

应用正在运行设计预览

Try this..

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/holo_red_dark"
    android:paddingLeft="8dp"
    android:paddingRight="8dp" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingBottom="8dp"
        android:paddingTop="8dp" >

        <TextView
            android:id="@+id/price_text"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:text="50 234 qwerty."
            android:textAppearance="@android:style/TextAppearance.Large" />

        <TextView
            android:id="@+id/discount_text"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:text="qwerty 12 3456."
            android:textAppearance="@android:style/TextAppearance.Small" />
    </LinearLayout>
</RelativeLayout>

In android studio, api of preview is 19, then in your emulator api is 18. it seem that dimen of @android:style/TextAppearance.Large and small was diferent.

Let try with same api in preview and excute code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM