【问题标题】:Android preview layoutAndroid 预览布局
【发布时间】:2019-02-20 16:42:47
【问题描述】:

我在 Android Studio 平台上的预览设计有问题。
我将附上两张照片:
设计师:here
我的手机:here
问题是 Android Studio 上的预览与我的手机显示的内容不完全相同。您肯定可以看到我的手机上没有显示描述字段。
XML 代码-sn-p 如下:

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

<RelativeLayout 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"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/yoyaku_image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/yoyakulogo2" />

    <android.support.v7.widget.LinearLayoutCompat
        android:id="@+id/linear_layout_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/yoyaku_image"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/phone_number"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dip"
            android:layout_marginTop="8dip"
            android:text="Phone number:" />

        <TextView
            android:id="@+id/actual_number"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dip"
            android:layout_marginTop="8dip"
            android:text="076767674764764" />
    </android.support.v7.widget.LinearLayoutCompat>

    <android.support.v7.widget.LinearLayoutCompat
        android:id="@+id/linear_layout_2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/linear_layout_1"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/location_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dip"
            android:layout_marginTop="8dip"
            android:text="Location:" />

        <TextView
            android:id="@+id/location_view_1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dip"
            android:layout_marginTop="8dip"
            android:text="74 rue des cascades 75020 Paris " />
    </android.support.v7.widget.LinearLayoutCompat>

    <android.support.v7.widget.LinearLayoutCompat
        android:id="@+id/linear_layout_3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/linear_layout_2"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/description_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dip"
            android:layout_marginTop="8dip"
            android:text="Description:" />

        <TextView
            android:id="@+id/description_view_2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dip"
            android:layout_marginTop="8dip"
            android:text=" record storespecialized in Electronic Music based in Paris" />

    </android.support.v7.widget.LinearLayoutCompat>

</RelativeLayout>


可以使用 ScrollView 解决问题,但最初我不想使用它。
这是什么原因造成的?

【问题讨论】:

    标签: android android-linearlayout android-relativelayout


    【解决方案1】:

    问题在于预览只是对布局外观的估计。 Android 手机有多种尺寸,您需要将布局包装在 ScrollView 中的原因是您的视图内容的高度大于物理设备的高度。现在这不一定是坏事,但也许你只是不想要ScrollView。要解决此问题,您可以使用 ConstraintLayout 之类的内容,然后设置正确的约束条件,您可以调整内容的大小以适应任何设备屏幕上的所有内容。

    Google 提供了很多很棒的资源,这是他们为ConstraintLayout 提供的简短培训文档:https://developer.android.com/training/constraint-layout/

    【讨论】:

    • 非常感谢。目前对ConstraintLayout不太熟悉,但我不知道预览只是一个估计。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-03
    • 2017-12-19
    • 2013-11-18
    • 1970-01-01
    • 2014-12-23
    • 2015-08-10
    • 2016-06-14
    相关资源
    最近更新 更多