Android开发实现圆形图片功能示例
作者:水中鱼之1999 时间:2023-07-12 08:43:54
本文实例讲述了Android开发实现圆形图片功能。分享给大家供大家参考,具体如下:
**绝对布局:通过直接给定控件起始坐标 ( x , y ) 和 ( w , l ) ,来生成控件。
圆形头像:CircleImageView的使用 **
注:在build.gradle中添加:
implementation 'de.hdodenhof:circleimageview:1.3.0'
XML布局文件:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/root"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Home"
android:layout_gravity="center">
<!--定义一个文本框用于存放头像,使用绝对布局-->
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/imageview"
android:layout_x="150dp"
android:layout_y="75dp"
android:layout_width="100dp"
android:layout_height="100dp"/>
<!--定义一个文本框,使用绝对定位-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="20dp"
android:layout_y="225dp"
android:text="用户名:"/>
<!--定义一个文本编辑框,使用绝对定位-->
<EditText
android:layout_x="80dp"
android:layout_y="215dp"
android:hint="邮箱/手机/用户名"
android:layout_width="wrap_content"
android:width="275dp"
android:layout_height="wrap_content"
android:singleLine="true" />
<!--定义一个文本框使用绝对定位-->
<TextView
android:layout_x="20dp"
android:layout_y="285dp"
android:text=" 密 码 :"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<!--定义一个文本编辑框,使用绝对定位-->
<EditText
android:layout_x="80dp"
android:layout_y="275dp"
android:hint="密码/验证码"
android:layout_width="wrap_content"
android:width="275dp"
android:layout_height="wrap_content"
android:password="true"
android:singleLine="true" />
<!--定义一个按钮,使用绝对定位-->
<Button
android:layout_x="100dp"
android:layout_y="350dp"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text=" 登 录 "/>
</AbsoluteLayout>
Java代码 动态设置头像:
//点击 切换图片
public class Home extends AppCompatActivity {
private LinearLayout mainLayout=null;
private ImageView iv=null;
//定义一个访问图片的数组
int[] images = new int[]{//放置你的图片
R.drawable.gass,
R.drawable.gonzhixiaochou
};
//用于图片切换
int currenImg = 0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);//显示manLayout
//创建CirImageView组件
final CircleImageView circleimageView01 = (CircleImageView) findViewById(R.id.imageview);
//设置CirImageView背景
circleimageView01.setImageResource(images[0]);
circleimageView01.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//切换背景
circleimageView01.setImageResource(images[++currenImg % images.length]);
}
});
}
}
效果:
希望本文所述对大家Android程序设计有所帮助。
来源:https://blog.csdn.net/qq_43377749/article/details/83868550
标签:Android,圆形图片
0
投稿
猜你喜欢
java中timer的schedule和scheduleAtFixedRate方法区别详解
2023-05-25 10:47:45
C#缓存之SqlCacheDependency用法实例总结
2023-04-14 10:31:37
详解Springboot之整合JDBCTemplate配置多数据源
2023-05-03 13:40:43
JavaMail与Spring整合过程解析
2022-07-06 23:53:54
SpringBoot从yml配置文件中读常用参数值实例方法
2021-07-01 11:12:04
JAVA使用hutool工具实现查询树结构数据(省市区)
2021-11-04 18:30:09
java实现双色球机选号码生成器
2022-10-05 07:41:33
分析那些不讲武德的SDK(构造使用规范)
2023-05-21 00:36:22
Java中IO流文件读取、写入和复制的实例
2023-08-12 03:23:29
Java中的Object.getClass()方法解析
2022-05-06 18:54:48
详解java操作Redis数据库的redis工具(RedisUtil,jedis工具JedisUtil,JedisPoolUtil)
2023-07-29 11:31:36
聊聊Java的switch为什么不支持long
2023-08-24 17:35:14
Android音视频开发之VideoView使用指南
2022-11-20 11:14:52
android仿微信通讯录搜索示例(匹配拼音,字母,索引位置)
2023-02-22 16:18:35
android 权限大全 分享
2023-03-30 18:06:22
Android Studio 3.0后出现AAPT2与“android.enableAapt2”问题的解决方法
2021-08-28 20:29:54
C#编程自学之开篇介绍
2023-12-16 07:58:55
java向下转型基础知识点及实例
2022-07-01 11:48:38
Android中的图片优化完全指南
2021-09-06 04:45:27
C# 禁用鼠标中间键的方法
2022-01-24 04:17:24