【问题标题】:Android cardView - how to fill in corner colors?Android cardView - 如何填充角落颜色?
【发布时间】:2020-06-25 15:36:45
【问题描述】:

如果是卡片视图,通常人们想要移除拐角半径周围的颜色,但我想保留它。我目前有一个看起来像这样的卡片视图:

我知道它看起来很棒,但我想要的是用另一种颜色填充角落。我怎样才能做到这一点?

这是我目前的代码:

 <androidx.cardview.widget.CardView
    android:id="@+id/my_card"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:focusable="true"
    app:cardCornerRadius="16dp"
    app:cardElevation="8dp"
    app:cardBackgroundColor="@color/_ribbon_pink_1"
    android:foregroundTint="@color/_green"
    app:behavior_peekHeight="200dp"
    app:cardPreventCornerOverlap="false">

如何用另一种颜色填充角落,使其看起来像这样,用另一种颜色填充角落:

不希望像在框架布局中那样添加背景。

【问题讨论】:

  • 在父视图中使用android:background(作为简单的LinearLayout)。
  • 我希望有一个不做背景的命令。我马上想到了。有没有其他方法可以在没有背景的情况下做到这一点?

标签: android android-cardview


【解决方案1】:
  • 试试这个。

     <androidx.cardview.widget.CardView
         android:id="@+id/card"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_gravity="center"
         android:foreground="?android:attr/selectableItemBackground"
         card_view:cardCornerRadius="15dp"
         card_view:cardElevation="3dp"
         card_view:cardUseCompatPadding="false">
    
         <RelativeLayout
             android:id="@+id/relativeLayout"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:gravity="center"
             android:padding="@dimen/item_title">
    
    
             <TextView
                 android:id="@+id/title"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:gravity="center"
                 android:minHeight="@dimen/item_cover_height"
                 android:text="title text test"
                 android:textSize="@dimen/item_title"
                 android:textStyle="bold" />
    
    
         </RelativeLayout>
    
     </androidx.cardview.widget.CardView>
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-25
    • 2012-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-29
    相关资源
    最近更新 更多