【问题标题】:How to show bottom shadow in android?如何在android中显示底部阴影?
【发布时间】:2020-04-17 04:21:26
【问题描述】:

如何在android中创建这种类型的布局看起来像图像

:

【问题讨论】:

标签: android


【解决方案1】:

使用MaterialCardView 并使用cardElevation

将此添加到 gradle 文件中以使用 material components

implementation 'com.google.android.material:material:1.2.0-alpha03'

style.xml

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

在你的 xml 中

 <com.google.android.material.card.MaterialCardView
            android:id="@+id/card"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:strokeWidth="1dp"
            app:strokeColor="@color/stroke_color"
            app:cardElevation="10dp"
            android:layout_margin="8dp">

            //add some view

        </com.google.android.material.card.MaterialCardView>

【讨论】:

  • 您也可以通过编程方式设置海拔。绝对是最好的答案。
  • @Jaydeep chatrola MaterialCardView 无法解析或未在 xml 中显示
  • 将写入的依赖项添加到您的 Gradle。
  • @DarshiDomadiya 使用材质主题
  • @DarshiDomadiya 根据您的需要提高卡片等级
【解决方案2】:

我认为你可以尝试使用cardView 并添加onclick func 来充当按钮

在cardView内部,你需要自定义TextView、ImageView等你想要的UI布局。

https://guides.codepath.com/android/using-the-cardview

https://material.io/develop/android/components/cards/

按钮阴影,我猜cardView也可以加阴影

How to add shadow on CardView aligned to bottom of parent

【讨论】:

    【解决方案3】:

    你尝试过:android:elevation="3dp" 在视图 xml 中吗?试试看。

    希望对您有所帮助!

    【讨论】:

      【解决方案4】:
      <androidx.cardview.widget.CardView
              android:id="@+id/maincard"
              android:layout_width="@dimen/_250sdp"
              android:layout_height="@dimen/_150sdp"
              android:layout_marginStart="@dimen/_5sdp"
              android:layout_marginEnd="@dimen/_15sdp"
              app:cardCornerRadius="@dimen/_12sdp"
              app:cardElevation="@dimen/_10sdp"
              app:cardPreventCornerOverlap="false">
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-02-28
        • 2022-12-13
        • 1970-01-01
        • 1970-01-01
        • 2017-04-24
        • 2015-01-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多