繁体   English   中英

Android Studio Linear Layout 定位不起作用?

[英]Android Studio Linear Layout positioning not working?

我正在尝试在线性布局内制作可滚动的卡片视图列表(位于框架布局中),但是我放置的第一个卡片视图位于错误的 position 中(我希望它位于线性布局的顶部,但它出现在底部)这是一个错误吗? 我该如何解决? 这是我的代码:

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="417dp"
    android:layout_marginTop="5dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/productDetails">

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <FrameLayout
                android:id="@+id/history_1"
                android:layout_width="380dp"
                android:layout_height="102dp"
                android:layout_marginTop="200dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
        </LinearLayout>
    </ScrollView>
</RelativeLayout>

这是图片:图片

将方向更改为水平

你的代码应该是这样的

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="417dp"
    android:layout_marginTop="5dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/productDetails">

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"> <!-- changed from vertical to horizontal -->

            <FrameLayout
                android:id="@+id/history_1"
                android:layout_width="380dp"
                android:layout_height="102dp"
                android:layout_marginTop="200dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
        </LinearLayout>
    </ScrollView>
</RelativeLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM