Giter Site home page Giter Site logo

ninepatchavatar's Introduction

Android自定义控件---仿微信群聊(九宫格)头像


博客地址http://blog.csdn.net/u012814441

Demo效果图如下

image

使用方法

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical">

        <per.edward.ninepatchavatar.TribeAvatar
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_margin="10dp"
            android:background="#F5F5F5">

            <com.facebook.drawee.view.SimpleDraweeView
                android:id="@+id/img_one"
                android:layout_width="30dp"
                android:layout_height="30dp"
                app:placeholderImage="@mipmap/ic_launcher" />

            <com.facebook.drawee.view.SimpleDraweeView
                android:id="@+id/img_two"
                android:layout_width="30dp"
                android:layout_height="30dp"
                app:placeholderImage="@mipmap/ic_launcher" />

            <com.facebook.drawee.view.SimpleDraweeView
                android:id="@+id/img_three"
                android:layout_width="30dp"
                android:layout_height="30dp"
                app:placeholderImage="@mipmap/ic_launcher" />

        </per.edward.ninepatchavatar.TribeAvatar>
</LinearLayout>

关于TribeAvatar的注意事项
1、在设置TribeAvatar宽度(layout_width)的时候必须给一个精确值例如 match_parent或者xxxdp,绝对不能设置 wrap_content。高度的话可以随便设置。因为最终的高度会和宽度一致。
2、子控件不能少于3个并且不能多于9个。否则图片会显示不出来。
3、子控件的宽度和高度可以随便设置,因为其宽度和高度最终都会由父控件TribeAvatar来决定。

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        SimpleDraweeView simpleDraweeViewOne = (SimpleDraweeView) findViewById(R.id.img_one);
        SimpleDraweeView simpleDraweeViewTwo = (SimpleDraweeView) findViewById(R.id.img_two);
        SimpleDraweeView simpleDraweeViewThree = (SimpleDraweeView) findViewById(R.id.img_three);

        simpleDraweeViewOne.setImageURI("https://github.com/EdwardSituwende/NinePatchAvatar/blob/master/img/111.jpg?raw=true");
        simpleDraweeViewTwo.setImageURI("https://github.com/EdwardSituwende/NinePatchAvatar/blob/master/img/222.jpg?raw=true");
        simpleDraweeViewThree.setImageURI("https://github.com/EdwardSituwende/NinePatchAvatar/blob/master/img/333.jpg?raw=true");
    }
}

ninepatchavatar's People

Contributors

edwardsituwende 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.