Giter Site home page Giter Site logo

roundimageview's Introduction

            Android自定义圆角图片
  • 序言

    在写项目的时候用到了圆角图片,可是又不想导入fresco ,glide这些比较大的库,虽然他们做的比较好,功能全,但是对于项目来说如果仅仅就是个圆角图片就导入的话,太浪费资源了,于是打算自定义一个.

  • 自定义View的顺序

    1. 选择继承View(包括widget中的控件),还是ViewGroup(报告四大布局)
    2. 重写onmeaure()方法 测量,重难点,需要了解测量模式.
    3. 重写 onlayout() 摆放位置,重难点(如果继承View不用重写此方法,反之)
    4. 重写 onDraw() 绘画 ,重难点(如果继承ViewGroup不用重写此方法,反之)
  • 自定义属性的顺序

    1. 在res/values,新建attrs.xml. >
    2. 自定义View,参考上面
    3. 再布局文件中,引入xmln(命名空间), xmlns:gs="http://schemas.android.com/apk/res-auto" ,gs属于自定义的,随便写
    4. 控件使用. * 方法一:添加libray,拷贝源码到项目中. ![](http://i.imgur.com/CMp1B3e.png). 在build中,引入依赖.
        ` compile project(':library')`.  
        
       * 方法二: 无需拷贝源码,在build中,直接引入依赖.  
       
       `compile 'com.gs:roundimageview:1.0.1'`
      

       * 布局文件中使用方法.   1 引入命名空间: xmlns:gs="http://schemas.android.com/apk/res-auto",注意空间名为gs 2 type:类型为circle,直接就是圆形,不需要半径; 类型为:round,需要定义圆弧半径,gs:type="round"       gs:borderRadius="15dp",注意需要跟type一起使用

  <com.example.library.RoundImageView
	        android:layout_marginTop="100dp"
	        android:id="@+id/circle"
	        android:layout_width="wrap_content"
	        android:layout_height="wrap_content"
	        android:layout_centerHorizontal="true"
	        android:src="@drawable/a"
	        gs:type="circle"/> 
</li>
  • 效果图

roundimageview's People

Contributors

gslovemy avatar

Watchers

James Cloos avatar feng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.