我有一个奇怪的行为,我无法弄清楚 - 我试图坚持视图到scrollview底部没有运气。我已经尝试过clipToPadding和fillViewport但它们都没有帮助。有帮助吗? 我的xml布局是 -
<LinearLayout>
<FrameLayout/>
<ScrollView>
<LinearLayout>
<LinearLayout/>
<RelativeLayout/> <-- This is the problematic view
</LinearLayout>
</ScrollView>
</LinearLayout>
我想将相对布局粘贴到底部,即使滚动视图比屏幕长度短,当clipToPadding设置为false时它确实适合屏幕但是相对布局刚刚放置在屏幕中间的线性布局之后他,当我在scrollview上将fillviewport设置为true(并删除cliptopadding)时,scrollview比屏幕长但不可滚动导致relativelayout“隐形”,有什么建议?
答案 0 :(得分:0)
尝试在滚动视图中使用相对布局而不是线性布局,并将相对布局与底部对齐。但我不确定它是否会在有内容后滚动。
<LinearLayout>
<FrameLayout/>
<ScrollView>
<RelativeLayout>
<LinearLayout android:alignParentTop="true" android:id="@+id/linearLayout" />
<RelativeLayout android:alignParentBottom="true" android:layoutBelow="@+id/linearLayout"/> <-- This is the problematic view
</LinearLayout>
</ScrollView>
检查这是否适合你。
答案 1 :(得分:0)
您可以尝试在ScrollView中使用ConstraintLayout:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
… Some elements with Constraints …
<TextView
android:id="@+id/last_but_one_element”
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@+id/some_previous_element"
app:layout_constraintTop_toBottomOf="@+id/last_element"
android:layout_marginBottom=“40dp"
app:layout_constraintVertical_bias="0.1"/>
<Button
android:id="@+id/last_element”
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>