布局在设备和仿真器上的显示方式不同

问题描述 投票:1回答:3

[我的布局在屏幕尺寸为5.0“,mdpi(480 * 800)的模拟器上正确显示。当我在屏幕尺寸为5.0”,196ppi(480 * 854)的设备上运行应用程序时,布局从底部被切除。

我尝试使用<supports-screens>,但没有任何区别。

layout.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/create_trip_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="top"
    android:orientation="vertical" >

    <LinearLayout
        style="@style/create_trip_activity_components_style"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:gravity="center_vertical"
        android:orientation="horizontal" >

        <EditText
            android:id="@+id/from_location"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:ems="10"
            android:hint="@string/from_location_hint"
            android:imeOptions="actionGo"
            android:imeActionLabel="Ok"
            android:inputType="text" >

            <requestFocus />
        </EditText>

        <Button
            android:id="@+id/use_current_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:onClick="useCurrentLocation"
            android:text="@string/use_current"
            android:textAppearance="?android:attr/textAppearanceSmall" />
    </LinearLayout>

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp"
        android:contentDescription="@string/swap_button_contentdescription"
        android:onClick="swapLocations"
        android:scaleType="fitStart"
        android:src="@drawable/swap" />

    <EditText
        android:id="@+id/to_location"
        style="@style/create_trip_activity_components_style"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:ems="10"
        android:gravity="left"
        android:hint="@string/to_location_hint"
        android:imeOptions="actionGo"
        android:imeActionLabel="Ok"
        android:inputType="text" >
    </EditText>

    <LinearLayout
        style="@style/create_trip_activity_components_style"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="25dp"
        android:gravity="center_vertical"
        android:orientation="horizontal" >

        <EditText
            android:id="@+id/departuretime_date"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="true"
            android:ems="10"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:gravity="center"
            android:hint="@string/departure_date_hint"
            android:inputType="datetime" >
        </EditText>

        <EditText
            android:id="@+id/departuretime_time"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="true"
            android:ems="10"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:gravity="center"
            android:hint="@string/departure_time_hint"
            android:inputType="datetime" >
        </EditText>

    </LinearLayout>

    <Button
        android:id="@+id/pick_match_create_trip"
        style="@style/big_centered_button_style"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="80dp"
        android:onClick="pickMatchesButtonClicked"
        android:text="@string/pick_your_matches" />

    <TextView
        style="@style/create_trip_activity_components_style"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="75dp"
        android:text="@string/current_location_textlabel"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <TextView
        android:id="@+id/current_location_text"
        style="@style/create_trip_activity_components_style"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_marginTop="5dp"
        android:text=""
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <ListView
        android:id="@+id/places_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="20dp"
        android:background="@color/white" >
    </ListView>

</LinearLayout>
android android-layout android-screen-support android-screen
3个回答
0
投票

唯一的方法是在xml布局中进行出色的编码,并在从头开始设计时,在GRAPHICAL LAYOUT中检查所有可用的屏幕方向和大小。


0
投票

请检查您是否为该特定布局选择了正确的主题。我也有同样的问题。


0
投票

它可能与图像密度有关,如果您使用的是720 dp的同一图像,则它可能会这样运行,对于480 * 800,电话屏幕的图像密度应为320 dp,对于480dp的图像密度应为480 dp。如Streak之类的Tweener平板电脑,以获取更多参考,请检查此]

320dp:典型的电话屏幕(240x320 ldpi,320x480 mdpi,480x800 hdpi等)。>>

480dp:诸如Streak(480x800 mdpi)之类的Tweener平板电脑。

600dp:7英寸平板电脑(600x1024 mdpi)。

720dp:10英寸平板电脑(720x1280 mdpi,800x1280 mdpi等)。

http://developer.android.com/guide/practices/screens_support.html

我有类似的问题,我为7英寸平板电脑使用了720 dp,720 * 1280的屏幕,并且屏幕被切断,获得600 dp的图片解决了我的问题,并且在模拟器上运行正常,但在真实环境下无法运行设备。我不确定该解决方案是否适合您!但是,祝你好运

© www.soinside.com 2019 - 2024. All rights reserved.