我有一個ConstraintLayout,我想在螢屏底部顯示一個按鈕。螢屏的主要區域是一個RecyclerView以防萬一。
無論如何,我想在按鈕上方有一個水平線視圖。
我嘗試了以下方法:
<?xml version="1.0" encoding="utf-8"?>
<ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@ id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:text="Some text here"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@ id/recycler"
app:layout_constraintTop_toBottomOf="@id/text"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="12dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginStart="16dp"
android:background="@color/red_color"
app:layout_constraintBottom_toBottomOf="@id/button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/recycler"
app:layout_constraintVertical_bias="0.887" />
<Button
android:id="@ id/button"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
android:text="Click Here"
/>
</ConstraintLayout>
但是虛擬視圖沒有顯示在按鈕上方。
我能做些什么來解決這個問題?
uj5u.com熱心網友回復:
<?xml version="1.0" encoding="utf-8"?><androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@ id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:text="Some text here"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@ id/recycler"
app:layout_constraintTop_toBottomOf="@id/text"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="12dp"
app:layout_constraintBottom_toTopOf="@ id/guideline"
android:layout_width="match_parent"
android:layout_height="0dp"/>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/black"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/recycler" />
<androidx.constraintlayout.widget.Guideline
android:id="@ id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.9" />
<Button
android:id="@ id/button"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@ id/guideline"
android:text="Click Here"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
這是可能對您有所幫助的作業解決方案。
uj5u.com熱心網友回復:
看一下這個
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@ id/text"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some text here" />
<androidx.recyclerview.widget.RecyclerView
android:id="@ id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/red_view"
android:layout_below="@id/text"
android:layout_marginTop="12dp" />
<View
android:id="@ id/red_view"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_above="@id/button"
android:layout_marginBottom="5dp"
android:background="#ff0000" />
<Button
android:id="@ id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Click Here" />
</RelativeLayout>
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/382628.html
標籤:安卓 安卓布局 android-constraintlayout
下一篇:輸入'{'x-access-token':任意;}|{'x-access-token'?:未定義;}'不可分配給型別'AxiosR
