Reputation: 148
the elevation is not working even after adding padding to the view, here is the Relative layout, what else I should add for a shadow in the image view.
<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>
Upvotes: 0
Views: 2295
Reputation: 240
Best is to use CardView and add the RelativeLayout inside the CardView and fill it with match_parent.
Then use 'elevation' attribute of CardView
<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>
Dependency for CardView
implementation 'com.android.support:cardview-v7:28.0.0'
Upvotes: -2
Reputation: 2491
I use the code below to add shadow to any View
that looks circular. Works on Lollipop and above.
myCircularImageView.setOutlineProvider(new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, view.getWidth(), view.getHeight());
}
});
myCircularImageView.setClipToOutline(true);
I don't encourage using CardView
because it makes your layout more complex.
Upvotes: 11
Reputation: 647
you can use cardview as parent layout of relative layout & give the elevation to cardview. It will give shadow to your imageview. Hope it will work for you.
<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>
Upvotes: 2
Reputation: 578
Easy way is to use textview in a card view and then add shadow to it using
android:elevation=""
, see this on how to use CardView.
Upvotes: -1