运行项目后组件被移动

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

我有两个问题:

  1. 运行项目时,组件的移动方式与设计时不同。
  2. 我无法滑动滚动视图来查看所有内容。

我是一名学生,在做项目时遇到了这些问题。 我英语不好,所以我必须使用谷歌翻译来写作。 我希望你能够明白。非常感谢。

这是我的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<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=".Families.CanidaeDetailActivity"
    android:background="@color/body">
    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <LinearLayout
            android:id="@+id/lnly_class"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:orientation="horizontal"
            app:layout_constraintTop_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <ImageView
                android:id="@+id/iv_back"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_gravity="center"
                android:layout_marginStart="25dp"
                android:layout_marginTop="0dp"
                android:src="@drawable/hinh_back" />
                <ImageView
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_gravity="center"
                    android:layout_marginStart="80dp"
                    android:src="@drawable/icon_voice"
                    android:contentDescription="TODO" />
                <TextView
                    android:id="@+id/txt_title"
                    android:layout_width="205dp"
                    android:layout_height="match_parent"
                    android:layout_marginStart="10dp"
                    android:gravity="center_vertical"
                    android:text="Lorem ipsum"
                    android:textStyle="bold"
                    android:textColor="@color/white"
                    android:textSize="16sp"
                    tools:ignore="RtlCompat" />
            <ImageView
                android:id="@+id/iv_translator"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_gravity="center"
                android:layout_marginStart="0dp"
                android:src="@drawable/icon_change_langue"
                />
        </LinearLayout>
        <FrameLayout
            android:id="@+id/fl_image"
            android:layout_width="match_parent"
            android:layout_height="385dp"
            android:background="@color/line1"
            app:layout_constraintTop_toBottomOf="@id/lnly_class"
            >
            <ImageView
                android:id="@+id/iv_canidae"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:adjustViaewBounds="true"
                android:scaleType="centerCrop"
                />
        </FrameLayout>
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fillViewport="true"
            app:layout_constraintTop_toBottomOf="@id/fl_image"
            tools:ignore="MissingConstraints">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                >
                <ImageView
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:src="@drawable/icon_voice"
                    android:layout_marginTop="20dp"
                    android:layout_marginStart="30dp"
                    />
                <TextView
                    android:id="@+id/tv_description"
                    android:layout_width="289dp"
                    android:layout_height="wrap_content"
                    android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris auctor fringilla feugiat. Sed condimentum convallis fringilla. Pellentesque non faucibus enim, sit amet condimentum velit. Curabitur tellus diam, elementum sed tristique vel, eleifend ac ex. Vivamus ex est, dignissim at accumsan posuere, tincidunt non augue. Praesent tempus tellus lacus, ac eleifend felis posuere suscipit. Phasellus facilisis arcu nec ultricies cursus. Integer pulvinar hendrerit augue, in facilisis odio dapibus ac. Ut interdum dolor ut efficitur ultrices. Nam tempus ex eget nunc tristique faucibus."
                    android:justificationMode="inter_word"
                    android:textSize="15sp"
                    android:textColor="@color/white"
                    android:layout_marginStart="10dp"
                    android:layout_marginTop="20dp"
                    />
            </LinearLayout>
        </ScrollView>
    </androidx.constraintlayout.widget.ConstraintLayout>
</RelativeLayout>

这里有一些照片:
When design
When running

android android-studio android-linearlayout android-scrollview
1个回答
0
投票

您提供的XML代码似乎不完整,并且不包含您定义ScrollView的部分。不过,我可以就您提到的问题提供一些一般性指导。

组件移动方式不同:

确保您使用适当的布局约束或其他布局参数来定位组件。在 LinearLayout 中,您指定了约束 (app:layout_constraintTop_toBottomOf="parent"),因此请确保正确设置这些约束。 如果您遇到组件放置问题,请考虑使用 ConstraintLayout 功能来更好地控制组件定位。 滚动问题:

如果您有一个 ScrollView 来包裹您的内容,请确保 ScrollView 的高度设置为wrap_content。这允许 ScrollView 根据内部内容调整其高度。 检查是否有任何子视图具有固定高度,这可能会阻止 ScrollView 滚动。如果内容太大,可能会被剪辑。 对于滚动问题,您可以像这样修改 XML:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Your existing layout code here -->

</ScrollView>

确保根据您的设计要求调整布局参数和约束。

如果您可以提供更多信息或完整的 XML 布局,我也许可以提供更具体的指导。此外,如果您使用任何特定的库或框架,它们的文档可能会深入了解常见问题和解决方案。

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