【问题标题】:Elevation on circular Image not woking Android圆形图像上的高程不适用于Android
【发布时间】:2018-11-23 09:55:16
【问题描述】:

即使在视图中添加填充后,海拔也不起作用,这是相对布局,我还应该为图像视图中的阴影添加什么。

  <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>

【问题讨论】:

    标签: java android shadow


    【解决方案1】:

    我使用下面的代码为任何看起来是圆形的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,因为它会使您的布局更加复杂。

    【讨论】:

      【解决方案2】:

      您可以将 cardview 用作相对布局的父布局并将高程指定给 cardview。它会给你的图像视图带来阴影。希望它对你有用。

        <android.support.v7.widget.CardView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:cardElevation="5dp"
            app:cardCornerRadius="5dp"
            card_view:cardBackgroundColor="@color/colortransperent">
       <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>
       </android.support.v7.widget.CardView>
      

      【讨论】:

      • 它是一个圆形图像,我正在尝试但它没有发生。
      • 它将高程添加到整个视图中,我想要的只是图像。上面已经回答了,还是很多!
      【解决方案3】:

      简单的方法是在卡片视图中使用 textview,然后使用 android:elevation="",CardView 使用方法见this

      【讨论】:

        【解决方案4】:

        最好是使用 CardView 并在 CardView 中添加 RelativeLayout 并用 match_parent 填充。

        然后使用 CardView 的 'elevation' 属性

        <android.support.v7.widget.CardView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:elevation="5dp">
        
                <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>
        
            </android.support.v7.widget.CardView>
        

        对 CardView 的依赖

        implementation 'com.android.support:cardview-v7:28.0.0'
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-12-15
          • 2015-10-17
          • 1970-01-01
          • 1970-01-01
          • 2019-04-30
          • 2012-12-12
          相关资源
          最近更新 更多