【问题标题】:Android Studio Linear Layout positioning not working?Android Studio 线性布局定位不起作用?
【发布时间】:2020-08-31 19:54:35
【问题描述】:

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

    <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>

图片如下: picture

【问题讨论】:

    标签: java xml android-studio android-linearlayout


    【解决方案1】:

    将方向更改为水平

    你的代码应该是这样的

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-19
      • 1970-01-01
      相关资源
      最近更新 更多