曲线图像视图角 android
Curve imageview corner android
从最近几天开始,我一直在尝试为我的视图实现曲线角。我想像这样设计我的 xml 图像:
或url:Sample Image
我只想要带有曲线角的图像。如果图像适合其父级,则宽度为 auto.So 可以显示完整图像。
我尝试使用 cardView
、Glide
、Picasso
和 com.makeramen.roundedimageview.RoundedImageView
库,但无法获得正确的结果。
adapterHome.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:background="@color/transparent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_5sdp"
android:layout_marginEnd="@dimen/_5sdp"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent">
<ProgressBar
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="100dp"
android:visibility="gone" />
<ImageView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/influencers"
android:scaleX="1"
android:scaleY="1"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:paddingTop="@dimen/_2sdp"
android:layout_marginStart="@dimen/_1sdp"
android:background="@color/light_transparent"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:paddingLeft="@dimen/_5sdp"
android:orientation="horizontal"
>
<ImageView
android:layout_width="@dimen/_12sdp"
android:layout_height="@dimen/_12sdp"
android:src="@drawable/ic_happy_smily"
android:layout_gravity="center"
/>
<TextView
android:id="@+id/total_reaction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/thumbnail"
android:text="3k"
android:textColor="@color/white"
android:layout_gravity="bottom"
android:gravity="start"
android:textSize="@dimen/_10sdp"
android:paddingLeft="@dimen/_5sdp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="center"
>
<ImageView
android:layout_width="@dimen/_15sdp"
android:layout_height="@dimen/_15sdp"
android:src="@drawable/ic_eye_watch_white"
android:layout_gravity="center"
/>
<TextView
android:id="@+id/total_watch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/thumbnail"
android:text="3k"
android:textColor="@color/white"
android:layout_gravity="bottom"
android:gravity="start"
android:textSize="@dimen/_10sdp"
android:paddingLeft="@dimen/_5sdp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="end"
>
<TextView
android:id="@+id/total_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/thumbnail"
android:text="0 Sec"
android:textColor="@color/white"
android:layout_gravity="bottom"
android:gravity="end"
android:textSize="@dimen/_10sdp"
android:paddingRight="@dimen/_5sdp"
/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
<TextView
android:id="@+id/post_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/_5sdp"
android:text="sdsds"
android:layout_gravity="top"
android:gravity="top"
android:layout_marginBottom="@dimen/_5sdp"
android:textSize="@dimen/_12sdp"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:enabled="true"
android:textColor="@color/black"
/>
</LinearLayout>
也代替了
<LinearLayout
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_5sdp"
android:layout_marginEnd="@dimen/_5sdp"
android:orientation="vertical">
</LinearLayout>
我试过用
CardView
但它不起作用。
<androidx.cardview.widget.CardView
android:id="@+id/card_view"
xmlns:card_view="https://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="@color/grey_300"
card_view:cardCornerRadius="10dp"
card_view:cardElevation="0dp"
card_view:cardUseCompatPadding="true">
</androidx.cardview.widget.CardView>
使用毕加索:
Transformation transformation = new RoundedTransformationBuilder()
.borderColor(Color.BLACK)
.cornerRadiusDp(30)
.oval(false)
.build();
Picasso.get()
.load(imageUrl)
.placeholder(R.drawable.influencers)
.error(R.drawable.influencers)
.transform(transformation)
.into(holder.thumbnail);
使用下面是我的输出:
Output
使用 cardview 并给卡片角半径。
在 cardview 中采用任何布局,然后使用该布局中的任何视图。
示例:
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="10dp"
app:cardElevation="0dp"
android:id="@+id/inercard"
app:cardBackgroundColor="#ffffff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="180dp"
android:id="@+id/imageview"
android:scaleType="fitXY"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
您只是将 id 设置为卡片视图,而不是这样做:
添加此 Gradle 卡片依赖项查看此内容:
<android.support.v7.widget.CardView
android:id="@+id/card_view"
xmlns:card_view="https://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="@color/grey_300"
card_view:cardCornerRadius="10dp"
card_view:cardElevation="5dp"
card_view:cardUseCompatPadding="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:background="@color/transparent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_5sdp"
android:layout_marginEnd="@dimen/_5sdp"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent">
<ProgressBar
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="100dp"
android:visibility="gone" />
<ImageView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/influencers"
android:scaleX="1"
android:scaleY="1"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:paddingTop="@dimen/_2sdp"
android:layout_marginStart="@dimen/_1sdp"
android:background="@color/light_transparent"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:paddingLeft="@dimen/_5sdp"
android:orientation="horizontal"
>
<ImageView
android:layout_width="@dimen/_12sdp"
android:layout_height="@dimen/_12sdp"
android:src="@drawable/ic_happy_smily"
android:layout_gravity="center"
/>
<TextView
android:id="@+id/total_reaction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/thumbnail"
android:text="3k"
android:textColor="@color/white"
android:layout_gravity="bottom"
android:gravity="start"
android:textSize="@dimen/_10sdp"
android:paddingLeft="@dimen/_5sdp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="center"
>
<ImageView
android:layout_width="@dimen/_15sdp"
android:layout_height="@dimen/_15sdp"
android:src="@drawable/ic_eye_watch_white"
android:layout_gravity="center"
/>
<TextView
android:id="@+id/total_watch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/thumbnail"
android:text="3k"
android:textColor="@color/white"
android:layout_gravity="bottom"
android:gravity="start"
android:textSize="@dimen/_10sdp"
android:paddingLeft="@dimen/_5sdp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="end"
>
<TextView
android:id="@+id/total_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/thumbnail"
android:text="0 Sec"
android:textColor="@color/white"
android:layout_gravity="bottom"
android:gravity="end"
android:textSize="@dimen/_10sdp"
android:paddingRight="@dimen/_5sdp"
/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
<TextView
android:id="@+id/post_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/_5sdp"
android:text="sdsds"
android:layout_gravity="top"
android:gravity="top"
android:layout_marginBottom="@dimen/_5sdp"
android:textSize="@dimen/_12sdp"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:enabled="true"
android:textColor="@color/black"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
使用 cardview ,scale type centercrop 并且如果 corener 不是 radius 然后添加属性 compactpadding=true,在大多数情况下这个属性忘记那里因为 card 没有得到角和图像重叠 cardview。
从最近几天开始,我一直在尝试为我的视图实现曲线角。我想像这样设计我的 xml 图像:
或url:Sample Image
我只想要带有曲线角的图像。如果图像适合其父级,则宽度为 auto.So 可以显示完整图像。
我尝试使用 cardView
、Glide
、Picasso
和 com.makeramen.roundedimageview.RoundedImageView
库,但无法获得正确的结果。
adapterHome.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:background="@color/transparent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_5sdp"
android:layout_marginEnd="@dimen/_5sdp"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent">
<ProgressBar
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="100dp"
android:visibility="gone" />
<ImageView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/influencers"
android:scaleX="1"
android:scaleY="1"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:paddingTop="@dimen/_2sdp"
android:layout_marginStart="@dimen/_1sdp"
android:background="@color/light_transparent"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:paddingLeft="@dimen/_5sdp"
android:orientation="horizontal"
>
<ImageView
android:layout_width="@dimen/_12sdp"
android:layout_height="@dimen/_12sdp"
android:src="@drawable/ic_happy_smily"
android:layout_gravity="center"
/>
<TextView
android:id="@+id/total_reaction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/thumbnail"
android:text="3k"
android:textColor="@color/white"
android:layout_gravity="bottom"
android:gravity="start"
android:textSize="@dimen/_10sdp"
android:paddingLeft="@dimen/_5sdp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="center"
>
<ImageView
android:layout_width="@dimen/_15sdp"
android:layout_height="@dimen/_15sdp"
android:src="@drawable/ic_eye_watch_white"
android:layout_gravity="center"
/>
<TextView
android:id="@+id/total_watch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/thumbnail"
android:text="3k"
android:textColor="@color/white"
android:layout_gravity="bottom"
android:gravity="start"
android:textSize="@dimen/_10sdp"
android:paddingLeft="@dimen/_5sdp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="end"
>
<TextView
android:id="@+id/total_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/thumbnail"
android:text="0 Sec"
android:textColor="@color/white"
android:layout_gravity="bottom"
android:gravity="end"
android:textSize="@dimen/_10sdp"
android:paddingRight="@dimen/_5sdp"
/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
<TextView
android:id="@+id/post_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/_5sdp"
android:text="sdsds"
android:layout_gravity="top"
android:gravity="top"
android:layout_marginBottom="@dimen/_5sdp"
android:textSize="@dimen/_12sdp"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:enabled="true"
android:textColor="@color/black"
/>
</LinearLayout>
也代替了
<LinearLayout
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_5sdp"
android:layout_marginEnd="@dimen/_5sdp"
android:orientation="vertical">
</LinearLayout>
我试过用
CardView
但它不起作用。
<androidx.cardview.widget.CardView
android:id="@+id/card_view"
xmlns:card_view="https://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="@color/grey_300"
card_view:cardCornerRadius="10dp"
card_view:cardElevation="0dp"
card_view:cardUseCompatPadding="true">
</androidx.cardview.widget.CardView>
使用毕加索:
Transformation transformation = new RoundedTransformationBuilder()
.borderColor(Color.BLACK)
.cornerRadiusDp(30)
.oval(false)
.build();
Picasso.get()
.load(imageUrl)
.placeholder(R.drawable.influencers)
.error(R.drawable.influencers)
.transform(transformation)
.into(holder.thumbnail);
使用下面是我的输出:
使用 cardview 并给卡片角半径。 在 cardview 中采用任何布局,然后使用该布局中的任何视图。
示例:
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="10dp"
app:cardElevation="0dp"
android:id="@+id/inercard"
app:cardBackgroundColor="#ffffff">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="180dp"
android:id="@+id/imageview"
android:scaleType="fitXY"
/>
</LinearLayout>
</androidx.cardview.widget.CardView>
您只是将 id 设置为卡片视图,而不是这样做:
添加此 Gradle 卡片依赖项查看此内容:
<android.support.v7.widget.CardView
android:id="@+id/card_view"
xmlns:card_view="https://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="@color/grey_300"
card_view:cardCornerRadius="10dp"
card_view:cardElevation="5dp"
card_view:cardUseCompatPadding="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:background="@color/transparent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_5sdp"
android:layout_marginEnd="@dimen/_5sdp"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent">
<ProgressBar
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="100dp"
android:visibility="gone" />
<ImageView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/influencers"
android:scaleX="1"
android:scaleY="1"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:paddingTop="@dimen/_2sdp"
android:layout_marginStart="@dimen/_1sdp"
android:background="@color/light_transparent"
>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:paddingLeft="@dimen/_5sdp"
android:orientation="horizontal"
>
<ImageView
android:layout_width="@dimen/_12sdp"
android:layout_height="@dimen/_12sdp"
android:src="@drawable/ic_happy_smily"
android:layout_gravity="center"
/>
<TextView
android:id="@+id/total_reaction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/thumbnail"
android:text="3k"
android:textColor="@color/white"
android:layout_gravity="bottom"
android:gravity="start"
android:textSize="@dimen/_10sdp"
android:paddingLeft="@dimen/_5sdp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="center"
>
<ImageView
android:layout_width="@dimen/_15sdp"
android:layout_height="@dimen/_15sdp"
android:src="@drawable/ic_eye_watch_white"
android:layout_gravity="center"
/>
<TextView
android:id="@+id/total_watch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/thumbnail"
android:text="3k"
android:textColor="@color/white"
android:layout_gravity="bottom"
android:gravity="start"
android:textSize="@dimen/_10sdp"
android:paddingLeft="@dimen/_5sdp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.33"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="end"
>
<TextView
android:id="@+id/total_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/thumbnail"
android:text="0 Sec"
android:textColor="@color/white"
android:layout_gravity="bottom"
android:gravity="end"
android:textSize="@dimen/_10sdp"
android:paddingRight="@dimen/_5sdp"
/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
<TextView
android:id="@+id/post_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/_5sdp"
android:text="sdsds"
android:layout_gravity="top"
android:gravity="top"
android:layout_marginBottom="@dimen/_5sdp"
android:textSize="@dimen/_12sdp"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:enabled="true"
android:textColor="@color/black"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
使用 cardview ,scale type centercrop 并且如果 corener 不是 radius 然后添加属性 compactpadding=true,在大多数情况下这个属性忘记那里因为 card 没有得到角和图像重叠 cardview。