如何在Android Studio上制作圆形的(带圆圈的)ImageView框?

编程入门 行业动态 更新时间:2024-10-26 17:18:28
本文介绍了如何在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="schemas.android/apk/res/android" xmlns:tools="schemas.android/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="schemas.android/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框?

本文发布于:2023-07-18 05:10:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141301.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:圆圈   圆形   如何在   Studio   Android

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!