簡體   English   中英

為什么我的應用在設計模式和仿真器上看起來不同?

[英]Why does my app look different on design mode and emulator?

我正在為一個應用編程,並為我的應用進行了自定義設計,問題是用戶界面在設計模式下看起來很完美,但是在運行時模式下(在仿真器和真實設備上)它看起來有所不同。 任何線索為什么??? 謝謝大家。

我完成了這項工作,以使模擬器中的ui看起來與設計模式下的ui相同。

在此處輸入圖片說明

這是一些代碼:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/bg"
    android:weightSum="8">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".8">
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".8">
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:gravity="center"
        android:layout_marginLeft="50sp"
        android:layout_marginRight="50sp"
        android:padding="4dp"
        android:layout_weight=".8">
    <Button
        android:text="Start"
        android:textColor="#0495d4"
        android:textAllCaps="false"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btnStart"
        android:layout_gravity="center" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:gravity="center"
        android:layout_marginLeft="50sp"
        android:layout_marginRight="50sp"
        android:padding="4dp"
        android:layout_weight=".8">
    <Button
        android:text="Followings"
        android:textColor="#0495d4"
        android:textAllCaps="false"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btnFollowings"
        android:layout_gravity="center" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=".8">
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:gravity="center"
        android:layout_weight=".8"
        android:orientation="horizontal"
        android:weightSum="3">
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight=".2"/>
        <LinearLayout
            android:layout_width="0dp"
            android:padding="2sp"
            android:layout_height="fill_parent"
            android:layout_weight="2.6">
    <EditText
        android:hint="Pin Code"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:textSize="16dp"
        android:textColor="@android:color/white"
        android:fontFamily="sans-serif-medium"
        android:textColorHint="@android:color/white"
        android:backgroundTint="@android:color/white"
        android:id="@+id/txtPinCode" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight=".2"/>

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:gravity="center"


        android:layout_weight=".8"
        android:orientation="horizontal"
        android:weightSum="3">
        <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight=".8"/>
        <LinearLayout
            android:layout_width="0dp"
            android:padding="10sp"
            android:gravity="center"

            android:layout_height="fill_parent"
            android:layout_weight="1.4">
    <Button
        android:text="Verify Pin"
        android:textColor="#0495d4"
        android:textAllCaps="false"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btnSavePin" 
        android:layout_gravity="center" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight=".8"/>

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2.4">

    </LinearLayout>
</LinearLayout>

設計看起來不同的原因是仿真器的屏幕配置與用於呈現設計預覽的屏幕配置不同。

在布局編輯器的下拉列表中(請參見屏幕截圖1 ),嘗試找到在尺寸和dpi上都與您的仿真設備匹配的配置。 這樣,預覽將更加准確。

設備選擇器

要找出您的仿真器具有哪種屏幕配置,只需轉到設備管理器(屏幕截圖2 ),然后參考分辨率列。

裝置經理

在不同的設備(設備仿真器)和不同版本的android上,標准樣式的不同值(textView,輸入字段等)。 設計師逐字顯示所有內容,設備小部件與標准android庫(特定版本)中的樣式混合在一起

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM