【问题标题】:Imageview not showing circular after image is selected选择图像后Imageview不显示圆形
【发布时间】:2019-08-08 14:31:23
【问题描述】:

我正在使用 Imageview 来显示图像,并且我正在使用背景可绘制形状 xml 来以圆形显示图像。

当我预加载图像时它工作正常,但我设置了 Onclick 侦听器,用户可以在其中编辑和更改用户个人资料图片,但是当用户选择图像时,它显示 rectunglar imageview 而不是 circulr。

我该如何解决它..

这里是xml代码

 <ImageView
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:id="@+id/itemImage1"
                android:background="@drawable/shape"
                android:layout_marginLeft="5dp"
                android:layout_marginBottom="20dp"
                android:src="@android:drawable/ic_menu_camera"
                android:cropToPadding="true"
                android:scaleType="fitXY" />
和背景形状 xml 文件是

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"   >

    <solid
        android:color="@color/white">
    </solid>

    <corners
        android:radius="7dp"   >
    </corners>


</shape>

提前致谢。

【问题讨论】:

标签: java android xml layout


【解决方案1】:

您可以使用此库。可以将其用于圆形图像视图。这很容易。

    <de.hdodenhof.circleimageview.CircleImageView
                            android:id="@+id/civProfilPicture"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_gravity="center"
                            android:background="@drawable/ic_camera"

                            />

来源:https://github.com/hdodenhof/CircleImageView

【讨论】:

  • 但我想要左侧的相机图标,以便用户知道他们可以从图标编辑图像。这里有这样的财产吗?
  • 该库将保持图像循环,它的作用@ProAcademy 我以前为此目的使用过它,效果很好。将其视为普通的图像视图...
  • @ProAcademy 您可以在 FrameLayout 中使用它。您可以在底部圈出 ımage 视图并在 cirleımage 上添加编辑图标。
【解决方案2】:

我想你想要这样。你可以使用 FrameLayout

  <FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="left"
    android:layout_margin="@dimen/small_padding"
    android:orientation="horizontal">

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/civProfilPicture"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginLeft="@dimen/small_padding"
        android:background="@drawable/ic_profil"
        />

    <ImageView
        android:layout_width="30dp"
        android:layout_height="30dp" 
        android:background="@drawable/ic_edit"

        />

</FrameLayout>

【讨论】:

    猜你喜欢
    • 2017-02-14
    • 2019-05-25
    • 1970-01-01
    • 2021-03-17
    • 2021-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-07
    相关资源
    最近更新 更多