Android开发实现圆形图片功能示例

发布时间:2019-08-08 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Android开发实现圆形图片功能示例脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了AndROId开发实现形图片功能。分享给大家供大家参考,具体如下:

**绝对布局:通过直接给定控件起始坐标 ( x , y ) 和 ( w , l ) ,来生成控件。

圆形头像:CircleimageView的使用 **

注:在build.gradle中添加:

 implementation 'de.hdodenhof:circleimageview:1.3.0'  

XML布局文件:

 <&#63;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开发实现圆形图片功能示例

更多关于Android相关内容感兴趣的读者可查看本站专题:《Android图形与图像处理技巧总结》、《Android开发入门与进阶教程》、《Android调试技巧与常见问题解决方法汇总》、《Android基本组件用法总结》、《Android视图View技巧总结》、《Android布局layout技巧总结》及《Android控件用法总结

android教程
脚本网站
android studio

脚本宝典总结

以上是脚本宝典为你收集整理的Android开发实现圆形图片功能示例全部内容,希望文章能够帮你解决Android开发实现圆形图片功能示例所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。