我有一个布局,我正在尝试使其占据屏幕一半的高度。但我得到这个结果。另外,我在回收站视图中使用的网格为2列,这也意味着一半的宽度。
这是我的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@drawable/boarder_no_corners"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="0.5">
<androidx.cardview.widget.CardView
android:id="@+id/productCardView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/productNameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="0dp"
android:layout_marginBottom="8dp"
android:layout_toStartOf="@+id/onHandQuantityTextView"
android:fontFamily="@font/open_sans_bold"
android:gravity="center"
android:text="TextView"
android:textColor="@color/color1"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_margin="7dp"
android:id="@+id/onHandQuantityTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/quantity_box"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="15sp"
android:padding="8dp"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
<ImageView
android:padding="8dp"
android:id="@+id/productImageView"
android:layout_width="150dp"
android:layout_height="150dp"
tools:srcCompat="@drawable/boxes"
android:gravity="center"
/>
</LinearLayout>
<TextView
android:id="@+id/productCategoryTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/color1"
android:textSize="16sp"
android:padding="4dp"
android:gravity="center"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
我尝试在“相对”视图和“纸牌视图”中使用高度,但似乎没有解决方法。感谢您的帮助。