android - 曲线图像视图角android
问题描述
从过去的很多天开始,我都在尝试为我的视图实现曲线角。我想像这样设计我的 xml:
或网址:示例图片
我想要的只是带有曲线角的图像。如果图像适合其父级,则宽度将自动显示。因此可以显示完整图像。
我尝试使用cardView
,Glide
和library 但无法获得正确的结果Picasso
。com.makeramen.roundedimageview.RoundedImageView
适配器主页.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);
使用下面是我的输出后: 输出
解决方案
您只是将 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>
推荐阅读
- sql - 函数 PL/SQL ORACLE
- android - 如何从 Kotlin 的 recyclerview 获取 Checkbox isChecked 数据
- java - JAVA 正则表达式识别值并对路径参数进行分类
- angular - Angular 11(或 9+)I18n 在启动时设置语言环境
- java - 具有非 void 返回值的方法的 Java Spring 异步异常处理
- activemq - 如何通过命令行获取 Apache ActiveMQ 的统计信息
- node.js - Connect-mongodb-session: TypeError: Cannot read property 'Store' of undefined (mongodb, nodejs, connect-mongodb-session)
- powershell - 不同计算机语言的日期转换出错
- c# - 反序列化列表
使用运行时的类型 - c# - 我可以在 Dapper 中使用查询方法来插入和更新行吗?