Android预览版面

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

我对Android Studio平台上的预览设计有疑问。 我会附上两张照片: 设计师:here 我的手机:here 问题是Android Studio上的预览显示与我的手机完全相同。您肯定可以看到我的手机上没有显示说明字段。 XML代码段如下:

<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个回答
0
投票

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

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

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