约束不使电话视图居中

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

我有一个奇怪的错误。我真的不知道为什么。

因此,在编辑器上,我的约束可以按我的意愿工作。但是在电话上却没有。

图片(我没有足够的声誉来显示图片。。::

android studio

phone problem

代码:

<?xml version="1.0" encoding="utf-8"?>
<layout
    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">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true"
        tools:context=".fragments.home.HomeFragment">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="some text"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/textView" />

            <TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="some text"
                app:layout_constraintBottom_toTopOf="@+id/textView2"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    </ScrollView>

</layout>

谢谢你!

android android-layout android-constraintlayout
2个回答
0
投票

您是否尝试将ConstraintLayout的高度设置为“ match_parent”?似乎您将其限制为TextViews的组合高度。

[另外,您不应以这种方式设置BottomToTop和TopToBottom,一个应该取决于父项。您可以通过在编辑器中选择两个视图,然后右键单击选择的Chain Vertically来轻松实现。


0
投票

没关系,刚发现问题。

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