如何在Android Studio上制作圆形的(带圆圈的)ImageView框? [英] How can I make rounded (circled) ImageView box on Android Studio?

查看:467
本文介绍了如何在Android Studio上制作圆形的(带圆圈的)ImageView框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Android Studio中创建圆角的图像视图而不是正方形(类似于Whats-app中的正方形).

I am trying to create rounded shape Image-view not the square shape in Android Studio (like the one from Whats-app).

这是我的xml文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@drawable/background"
    tools:context="com.example.ska89.xxxxxx.MainActivity">

    <ImageView
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:id="@+id/imageView2"
        android:src="@drawable/logo"
        android:layout_marginTop="64dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:adjustViewBounds="false"
        android:clickable="false" />
</RelativeLayout>

谢谢.

推荐答案

在您的drawable文件夹中创建一个xml文件(例如circle_shape.xml),然后编写类似以下的代码

Create a xml file e.g circle_shape.xml in your drawable folder and write the following code something like this

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

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

    <size
        android:width="50dp"
        android:height="50dp"/>
</shape>

然后在您的imageView中使用circle_shape.xml作为背景

then use this circle_shape.xml in your imageView as background something like this

<ImageView
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:id="@+id/imageView2"
    android:src="@drawable/logo"
    android:layout_marginTop="64dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:adjustViewBounds="false"
    android:background="@drawable/circle_shape"
    android:clickable="false" />

这篇关于如何在Android Studio上制作圆形的(带圆圈的)ImageView框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆