android - 在 Android 的底页顶部添加图像
问题描述
如何在 Android 的底部工作表顶部添加图像?看到这张图片
我试过这个,但它不起作用。我想要如图所示的透明度。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@id/myBottomLL"
app:layout_anchorGravity="top|center" />
<LinearLayout
android:id="@+id/myBottomLL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/background" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
解决方案
按照这些链接。如何使背景透明: https ://medium.com/@manuaravindpta/transparent-background-for-bottomsheetdialog-396a1a646f1b
如何使底页全屏: https ://medium.com/better-programming/bottom-sheet-android-340703e114d2
对于圆形图像视图: https ://github.com/hdodenhof/CircleImageView
只需像这样在顶部添加一个透明视图。
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/topImage"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_gravity="center_horizontal|top"
android:elevation="6dp"
android:src="@drawable/ic_account_circle"
app:civ_border_color="@color/colorAccent"
app:civ_border_width="2dp"
app:civ_circle_background_color="@android:color/white" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/transparentRegion"
android:layout_width="match_parent"
android:layout_height="56dp"
android:orientation="horizontal" />
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/white"
app:elevation="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="end"
android:orientation="horizontal">
<ImageButton
android:id="@+id/closeBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="16dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:src="@drawable/ic_close"
android:tint="@android:color/black" />
</LinearLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/bottomSheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:fillViewport="true">
<LinearLayout
android:id="@+id/other_content_goes_here"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Other Content"
android:textSize="24sp" />
<View
android:id="@+id/extraSpace"
android:layout_width="match_parent"
android:layout_height="800dp" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
设置 BottomSheetDialogFragment 的主题。您还可以添加一个 BottomSheetCallback 并在向上滚动时减小顶部透明空间的高度
推荐阅读
- javascript - 如何在动态函数中按嵌套对象值排序
- discord.js - 公会删除事件返回未定义
- visual-studio - NuGet 发行说明
- hibernate - Hibernate Transient 在 Kotlin 中不起作用
- java - 为什么我的代码会抛出“ImageStorageException:图像数据没有加载器”
- excel - Excel:从唯一标识符下方的数据中提取数据
- mongodb - Spring数据Mongodb在mongo repository.java中声明String类型datetime
- javascript - 永远不会触发 Alexa LaunchRequest
- json - 将 Pandas DataFrame 转换为 JSON
- javascript - VueJS - 在 div 中打印字符串时的奇怪行为