gpt4 book ai didi

安卓预览布局

转载 作者:行者123 更新时间:2023-11-30 05:04:30 27 4
gpt4 key购买 nike

我在 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com