java - Android 上圆形图像的高程不起作用

标签 java android shadow

即使在向 View 添加填充后,标高也不起作用,这是相对布局,我还应该为 ImageView 中的阴影添加什么。 enter image description here

  <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toBottomOf="@+id/tvContinueWith"
        android:layout_marginTop="@dimen/_10dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent">

        <ImageView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imgFb"
            android:layout_alignParentStart="true"
            android:layout_centerInParent="true"
            android:elevation="@dimen/_5dp"
            android:src="@drawable/fb"
            />

        <ImageView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imgGoogle"
            android:layout_toRightOf="@+id/imgFb"
            android:layout_marginLeft="@dimen/_5dp"
            android:layout_centerInParent="true"
            android:src="@drawable/google"
            android:elevation="@dimen/_5dp"
            />

    </RelativeLayout>

最佳答案

我使用下面的代码为任何看起来呈圆形的View添加阴影。适用于 Lollipop 及以上版本。

myCircularImageView.setOutlineProvider(new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            outline.setOval(0, 0, view.getWidth(), view.getHeight());
        }
    });
    myCircularImageView.setClipToOutline(true);

我不鼓励使用 CardView 因为它会使您的布局更加复杂。

关于java - Android 上圆形图像的高程不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53444332/

相关文章:

java - Android 定时器/时钟

ios - 带阴影的 UIView,仅圆顶角和 mask 底边

android - robolectric 的一些方法找不到影子方法怎么办?

java - 了解 hibernate @Type 注解

android - 在 onReceive 中处理多个 intent.getStringExtra 的干净方法?

android - INQ Cloud Touch调试

javascript - three.js中的透明阴影

java - Fork-join: fork 所有子任务或为当前线程留下一个子任务

java - 如何使用 java 从 .pls 文件流式传输 url?

java - 编辑字段奇怪的高度