安卓工作室线性布局定位不起作用?



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

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

最新更新