我想在回收器視圖中實作這種型別的動態高度的網格布局。如果一個單元格有兩行,那么同一行的其他單元格也應該有相同的高度,盡管其他單元格有一行。
這是我的行檔案代碼 :
<?xml version="1.0" encoding="utf-8"? >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" >。
android:layout_width="match_parent"。
android:layout_height="wrap_content"。
android:layout_marginRight="-4dp"。
android:layout_marginTop="-4dp"。
android:layout_marginBottom="-20dp"。
android:layout_marginLeft="-12dp"/span>>
<androidx.cardview.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto"/span>
xmlns:tools="http://schemas.android.com/tools"。
android:id="@ id/cvHomeItem"。
android:layout_width="match_parent"。
android:layout_height="wrap_content"。
app:cardBackgroundColor="@color/white"。
app:cardCornerRadius="@dimen/margin_8"。
app:cardElevation="@dimen/margin_8"。
app:cardUseCompatPadding="true">
<LinearLayout
android:id="@ id/llChild"
android:layout_width="match_parent"。
android:layout_height="wrap_content"。
android:layout_margin="@dimen/_6ssp"/span>
android:gravity="center_vertical"。
android:orientation="vertical">
<LinearLayout。
android:layout_width="match_parent"/span>
android:layout_height="wrap_content"。
android:layout_marginBottom="@dimen/minus_margin_2"
android:gravity="center_vertical"。
android:weightSum="1">>
<ImageView
android:id="@ id/ivImage"
android:layout_width="@dimen/margin_24"/span>
android:layout_height="@dimen/margin_24"。
android:layout_marginLeft="@dimen/margin_2"。
android:scaleType="centerInside"。
tools:src="@drawable/ic_announcement"
android:contentDescription="@string/app_name"/span> />
<LinearLayout
android:layout_width="match_parent"/span>
android:layout_height="wrap_content"。
android:gravity="end">
<TextView。
android:id="@ id/tvDays"
android:layout_width="wrap_content"
android:layout_height="wrap_content"。
android:layout_marginStart="@dimen/margin_12"
android:gravity="center_vertical"。
android:lines="2"
android:textColor="@color/colorText"/span>
android:textSize="@dimen/_11ssp"。
tools:text="3.5 天(s)" />
</LinearLayout>
</LinearLayout>/span>
<TextView
android:id="@ id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"。
tools:text="年假"
android:textColor="@color/colorText"。
android:textSize="@dimen/_11ssp"/span> />
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>/span>
如果有任何澄清或需要任何代碼,請告訴我。謝謝你!
uj5u.com熱心網友回復:
使你的線性布局("@ id/llChild")的高度與parent相匹配
<? xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"/span>
android:layout_width="match_parent"。
android:layout_height="wrap_content"。
android:layout_marginRight="-4dp"。
android:layout_marginTop="-4dp"。
android:layout_marginBottom="-20dp"。
android:layout_marginLeft="-12dp"/span>>
<androidx.cardview.widget.CardView xmlns:app="http://schemas.android.com/apk/res-auto"/span>
xmlns:tools="http://schemas.android.com/tools"。
android:id="@ id/cvHomeItem"。
android:layout_width="match_parent"。
android:layout_height="wrap_content"。
app:cardBackgroundColor="@color/white"。
app:cardCornerRadius="@dimen/margin_8"。
app:cardElevation="@dimen/margin_8"。
app:cardUseCompatPadding="true">
<LinearLayout
android:id="@ id/llChild"
android:layout_width="match_parent"。
android:layout_height="match_parent" <=correction。
android:layout_margin="@dimen/_6ssp"。
android:gravity="center_vertical"。
android:orientation="vertical">
.....
</LinearLayout>/span>
</androidx.cardview.widget.CardView>
</LinearLayout>/span>
uj5u.com熱心網友回復:
試試這個
<androidx.cardview.widget.CardView。
xmlns:android="http://schemas.android.com/apk/res/android"/span>
xmlns:app="http://schemas.android.com/apk/res-auto"。
android:id="@ id/cvItemMain"。
android:layout_width="match_parent"。
android:layout_height="wrap_content"。
android:layout_margin="6dp"。
android:orientation="vertical"。
app:cardCornerRadius="6dp"/span>
app:cardElevation="0dp"。
app:layout_constraintStart_toStartOf="father"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout。
android:layout_width="match_parent"
android:layout_height="match_parent"/span>>
<ImageView
android:id="@ id/ivLogo"
android:layout_width="match_parent"。
android:layout_height="0dp"。
android:padding="6dp"/span>
android:src="@drawable/ic_your_image"。
app:layout_constraintBottom_toTopOf="@id/tvName"
app:layout_constraintDimensionRatio="1:1"。
app:layout_constraintEnd_toEndOf="parent"。
app:layout_constraintStart_toStartOf="father"
app:layout_constraintTop_toTopOf="parent"/span> />
<TextView
android:id="@ id/tvName"
android:layout_width="0dp"/span>
android:layout_height="wrap_content"。
android:layout_marginStart="12dp"。
android:gravity="bottom"。
android:maxLines="2"。
android:minLines="2"。
android:text="Text 1"/span>
android:textColor="#000"/span>
android:textSize="14sp"/span>
app:layout_constraintBottom_toBottomOf="@id/tvPrice"
app:layout_constraintStart_toStartOf="@id/ivLogo"。
app:layout_constraintTop_toBottomOf="@id/ivLogo"。
app:layout_constraintWidth_percent="0.8"/span> />
<TextView
android:id="@ id/tvPrice"
android:layout_width="0dp"/span>
android:layout_height="wrap_content"。
android:layout_marginTop="4dp"。
android:layout_marginBottom="4dp"。
android:maxLines="1"。
android:minLines="1"。
android:text="Text 2"/span>
android:textColor="#F56114"/span>
android:textSize="14sp"。
android:textStyle="bold"/span>
app:layout_constraintBottom_toBottomOf="parent"。
app:layout_constraintStart_toStartOf="@id/tvName"
app:layout_constraintTop_toBottomOf="@id/tvName"/span> />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/313056.html
標籤:
上一篇:從一個物件/陣列創建UL串列

