圆形图像的高度不起作用 Android
Elevation on circular Image not woking Android
即使在视图中添加填充后,高度也不起作用,这是相对布局,我还应该为图像视图中的阴影添加什么。
<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>
简单的方法是在卡片视图中使用 textview,然后使用
android:elevation=""
,请参阅 this 了解如何使用 CardView。
您可以使用 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>
我使用下面的代码为任何看起来像圆形的 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
,因为它会使您的布局更加复杂。
最好是使用 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'
即使在视图中添加填充后,高度也不起作用,这是相对布局,我还应该为图像视图中的阴影添加什么。
<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>
简单的方法是在卡片视图中使用 textview,然后使用
android:elevation=""
,请参阅 this 了解如何使用 CardView。
您可以使用 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>
我使用下面的代码为任何看起来像圆形的 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
,因为它会使您的布局更加复杂。
最好是使用 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'