【问题标题】:How to add circle image for outline & add one more image view with center inside it in android using Constraint Layout如何使用约束布局在 android 中为轮廓添加圆形图像并在其中添加一个带有中心的图像视图
【发布时间】:2021-08-12 14:44:55
【问题描述】:

我的要求是我需要在中间添加一个带有36dp 宽度和高度的圆形图像,再添加一个图标的图像视图(宽度和高度环绕内容) 下面是我尝试使用约束布局实现的图像。

如何使用约束布局来达到同样的效果? 任何帮助表示赞赏[![在此处输入图像描述][1]][1]

【问题讨论】:

    标签: android layout imageview android-constraintlayout


    【解决方案1】:
     <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>
    

    【讨论】:

    • 我正在尝试使用约束布局 & 圆应该是 36 dp & 图像应该扭曲到中心
    • 只需要将RelativeLayout改为Constraint Layout并将其大小改为36dp即可。并为 imageview 添加这些属性: app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"
    【解决方案2】:

    在您的 ImageView 中使用 background 属性并将您的轮廓添加到其中,并使用 src 属性在 imageview 中添加您想要在其中显示的图片。无论您使用哪个layout(约束、线性、相对等),这都会起作用。

    【讨论】:

      猜你喜欢
      • 2019-05-04
      • 1970-01-01
      • 2015-04-26
      • 2021-12-10
      • 1970-01-01
      • 1970-01-01
      • 2021-09-29
      • 1970-01-01
      相关资源
      最近更新 更多