安卓预览布局

标签 android android-linearlayout android-relativelayout

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

<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 手机有多种尺寸,您需要将布局包裹在 ScrollView 中的原因是 View 内容的高度大于物理设备的高度。现在这不一定是坏事,但也许您只是不想要 ScrollView。要解决此问题,您可以使用 ConstraintLayout 之类的东西,然后设置正确的约束将允许您调整内容的大小以适应任何设备屏幕上的所有内容。

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

关于安卓预览布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54791349/

相关文章:

android - TextView 未在 Android 的 onResume 中更新

android - : myView. getLayoutParams().height = screenHeight 和 myView.setLayoutParams(lp) 之间的区别?

android - 如何仅使 View 的一部分(在运行时添加)覆盖/重叠相邻 View ?

android - 如何实现LinearLayout标题/标签

android - 如何在保留字符状态和图像的情况下向自动完成 TextView 动态添加建议

android - 需要有关 Android 轨迹球事件的帮助

java - LocationManager requestLocationUpdates minTime OR minDistance

android - 如何在除底部之外的线性布局周围添加边框?

android - 手动定义布局参数,意味着我想使用我的值来定义布局的边界

android - Jetpack Compose 中的 @Stable 和 @Immutable 注解是什么意思?