跳至主要內容

AndroidLiquidGlassView

小于 1 分钟

AndroidLiquidGlassView

XML布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- 内容容器 -->
    <FrameLayout
        android:id="@+id/content_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:id="@+id/images"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:src="@drawable/image" />

        </RelativeLayout>
    </FrameLayout>

    <!-- 液态玻璃视图 -->
    <com.qmdeve.liquidglass.widget.LiquidGlassView
        android:id="@+id/liquidGlassView"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_centerInParent="true" />
</RelativeLayout>

绑定采样源

Java
ViewGroup content = findViewById(R.id.content_container);
LiquidGlassView liquidGlassView = findViewById(R.id.liquidGlassView);

liquidGlassView.bind(content);

API 参考

方法描述默认值
bind(ViewGroup source)绑定采样源-
setCornerRadius(float px)设置圆角半径 (px) (0dp-99dp)40dp
setRefractionHeight(float px)设置折射高度 (px) (12dp-50dp)20dp
setRefractionOffset(float px)设置折射偏移 (px) (20dp-120dp)70dp
setTintColorRed(float red)设置色调(R) (0f-1f)1.0f
setTintColorGreen(float green)设置色调(G) (0f-1f)1.0f
setTintColorBlue(float blue)设置色调(G) (0f-1f)1.0f
setTintAlpha(float alpha)设置色调可见度 (0f-1f)0.0f
setDispersion(float dispersion)设置色散效果 (0f-1f)0.5f
setBlurRadius(float radius)设置模糊半径 (0dp-50dp)0f
setDraggable(boolean enable)启用/禁用拖动true