是否可以调整卡片视图的左侧高度?

问题描述 投票:0回答:2

我的CardView对准屏幕顶部。 CardView内部有一个ImageView,我只想调整CardView右侧的高度,如下图所示。这可能吗?

enter image description here

  <androidx.cardview.widget.CardView
  android:layout_width="0dp"
  android:layout_height="0dp"
  app:layout_constraintWidth_percent="1"
  app:layout_constraintHeight_percent="0.4"
  app:layout_constraintEnd_toEndOf="parent"
  app:layout_constraintStart_toStartOf="parent"
  app:layout_constraintTop_toTopOf="parent"
  app:cardElevation="10dp"
  app:cardCornerRadius="0dp">
    <ImageView
       android:id="@+id/bngCover"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       app:srcCompat="@drawable/explore2"
       android:scaleType="centerCrop"/>
</androidx.cardview.widget.CardView>
android user-interface imageview cardview
2个回答
1
投票

除了半径,CardViews本质上通常是矩形的;因此,使用CardView无法轻松实现

最佳建议是创建自己的资源文件。这样,您可以定义希望视图的外观,并仍然为其提供所需的属性(高程,半径等)。

要了解如何创建可绘制资源文件,请签出this tutorial。您也可以在ShapeDrawables here上阅读Android文档。

我希望这会有所帮助。编码愉快!


0
投票

CardView没有仅可更改侧面高度的属性。在这种情况下,您必须改为创建自定义梯形形状,如下所示:

How to build trapezoid shape in xml android?

© www.soinside.com 2019 - 2024. All rights reserved.