【发布时间】:2021-08-12 14:44:55
【问题描述】:
我的要求是我需要在中间添加一个带有36dp 宽度和高度的圆形图像,再添加一个图标的图像视图(宽度和高度环绕内容)
下面是我尝试使用约束布局实现的图像。
如何使用约束布局来达到同样的效果? 任何帮助表示赞赏[![在此处输入图像描述][1]][1]
【问题讨论】:
标签: android layout imageview android-constraintlayout
我的要求是我需要在中间添加一个带有36dp 宽度和高度的圆形图像,再添加一个图标的图像视图(宽度和高度环绕内容)
下面是我尝试使用约束布局实现的图像。
如何使用约束布局来达到同样的效果? 任何帮助表示赞赏[![在此处输入图像描述][1]][1]
【问题讨论】:
标签: android layout imageview android-constraintlayout
<RelativeLayout
android:id="@+id/rltCustomerAvatar"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginStart="14dp"
android:background="@drawable/background_circle_highlight"
android:visibility="@{ customerViewModel.isLoggedIn() ? View.VISIBLE : View.GONE }"
>
<ImageView
android:id="@+id/imgChat"
android:layout_width="33dp"
android:layout_height="33dp"
android:layout_marginTop="8dp"
android:padding="8dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_chat_star_page"
android:layout_centerInParent="true"
/>
</RelativeLayout>
AND background_circle_higlight
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
>
<solid android:color="#fb6834"/>
</shape>
【讨论】:
在您的 ImageView 中使用 background 属性并将您的轮廓添加到其中,并使用 src 属性在 imageview 中添加您想要在其中显示的图片。无论您使用哪个layout(约束、线性、相对等),这都会起作用。
【讨论】: