android - ImageView 的圆形背景

标签 android android-imageview android-drawable android-image android-shape

我正在尝试放置三个带有圆形背景的 ImageView 。我还画了一个圆形。

preview

但背景不是圆形显示椭圆。

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/contactphone"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:src="@drawable/phonecall"
            android:layout_margin="10dp"
            android:background="@drawable/contact_icon_round"
            android:layout_height="75dp" />

        <ImageView
            android:id="@+id/contactemail"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:src="@drawable/mail"
            android:layout_margin="10dp"
            android:background="@drawable/contact_icon_round"
            android:layout_height="75dp" />

        <ImageView
            android:id="@+id/contactlocation"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:src="@drawable/location"
            android:layout_margin="10dp"
            android:background="@drawable/contact_icon_round"
            android:layout_height="75dp" />
            android:layout_gravity="fill_vertical" />
    </LinearLayout>

圆形可绘制对象:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
    <solid android:color="@color/white"/>
    <size android:width="5dp" android:height="5dp"/>
</shape>

有问题但无法找出错误?

谢谢!

最佳答案

利用这种布局,

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="15dp"
    android:orientation="horizontal"
    xmlns:android="http://schemas.android.com/apk/res/android"
    >

  <LinearLayout
      android:layout_width="0dp"
      android:layout_weight="1"
      android:layout_height="75dp"
      >
  <ImageView
      android:id="@+id/contactphone"
      android:layout_width="75dp"
      android:src="@drawable/phonecall"
      android:layout_margin="10dp"
      android:background="@drawable/contact_icon_round"
      android:layout_height="75dp" />
  </LinearLayout>
  <LinearLayout
      android:layout_width="0dp"
      android:layout_weight="1"
      android:layout_height="75dp"
      >
  <ImageView
      android:id="@+id/contactemail"
      android:layout_width="75dp"
      android:src="@drawable/mail"
      android:layout_margin="10dp"
      android:background="@drawable/contact_icon_round"
      android:layout_height="75dp" />
  </LinearLayout>
  <LinearLayout
      android:layout_width="0dp"
      android:layout_weight="1"
      android:layout_height="75dp"
      >
  <ImageView
      android:id="@+id/contactlocation"
      android:layout_width="75dp"
      android:src="@drawable/location"
      android:layout_margin="10dp"
      android:background="@drawable/contact_icon_round"
      android:layout_height="75dp" />
  </LinearLayout>
</LinearLayout>

由于宽度和高度不均匀,背景显示为椭圆形。

希望对您有所帮助。

关于android - ImageView 的圆形背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50720530/

相关文章:

android - 构建自定义 Activity 堆栈

android - 如何在android中实现图片 ScrollView ?

android - 在 ImageView 顶部绘制位图/ Canvas

java - Android 上 AWS Rekognize 的一部分 CompareFacesRequest 出现错误

android - Cordova 平台添加 android 在列出 Android 目标时不起作用

android - 向可绘制形状添加文本

java - Android 比较背景颜色和颜色

android - 我们可以画一个使用 Path 对象的圆吗? [在参数中,如 drawPath()]

android - ListPopupWindow : setWidth, setHeight没有效果

android - 在 scrollview android 中全屏显示图像