【问题标题】:Why there is a difference between my app in a real device and the layout preview in android studio为什么我在真实设备中的应用程序与 android studio 中的布局预览之间存在差异
【发布时间】:2018-07-21 13:40:20
【问题描述】:

应用说明:- 带有 listView 的简单应用(方向:水平)

问题是:- 当我在真实设备上运行应用程序时,我发现所有视图方向都颠倒了

这是 android studio 上的一个项目:- app preview on android studio

但是当它在真实设备上运行时,它看起来像这样 app on a real device

这是我的布局(item.xml)代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:id="@+id/item_layout_id"
    android:padding="20dp">


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/mag_id"
        android:layout_weight="1"
        android:text="7.1"
        android:textColor="#302f2f"
        android:textSize="18sp"/>


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/country_id"
        android:layout_weight="1"
        android:text="Egypt"
        android:textColor="#302f2f"
        android:textSize="18sp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/date_id"
        android:layout_weight="1"
        android:text="July 21,2018"
        android:textColor="#302f2f"
        android:textSize="18sp"/>

</LinearLayout>

我想在真实设备上显示来自 android studio 预览的相同设计 具有相同的视图方向。

那么问题是什么,我该如何解决。

【问题讨论】:

  • 您可以将预览更改为从右到左的语言环境
  • 这是因为您的手机尺寸和预览版面尺寸的差异。

标签: android xml


【解决方案1】:

这是由于屏幕尺寸和显示分辨率之间的差异,您在工作室中设计的布局在您在布局编辑器中选择的确切屏幕尺寸或分辨率上可能看起来不错,但这可能不是每个设备都是如此,在这种情况下是您的设备。 您可以参考this线程以获得更详细的问题解决方案

【讨论】:

    【解决方案2】:

    你应该检查两三件事:

    1- 你的 ListView 父布局是否在 XML 中有 layoutDirection

    2- 您是否在代码中的任何位置调用了 getWindow().setLayoutDirection(LayoutDirection.RTL) 方法?

    3- 如果您的列表 activityfragment 没有编号 2,那么您应该检查您的适配器类,看看是否有任何关于 ItemView 方向的代码。

    4- 如果这与您无关,请尝试更改预览 android 版本和预览大小。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 2019-07-18
      相关资源
      最近更新 更多