实训第二周(1)

本周,我接着完成了在上一篇博客提到的未完成的几处


一.自定义图标控件ChangeColorIconWithText

MainActivity中的mIndicatorMsg, mIndicatorContract, mIndicatorMe都为ChangeColorWithText

这个自定义控件用于实现当手指滑动在底部Tab中的3个view中选择时,这个自定义控件可变色(渐变效果)

1.自定义属性

自定义属性设置为图标(icon)、图标颜色(color)、文字(text)、文字大小(text_size)

自定义属性:attr.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <attr name="icon" format="reference"/>
    <attr name="color" format="color"/>
    <attr name="text" format="string"/>
    <attr name="text_size" format="dimension"/>

    <declare-styleable name="ChangeColorIconWithText">
        <attr name="icon"/>
        <attr name="color"/>
        <attr name="text"/>
        <attr name="text_size"/>
    </declare-styleable>
</resources>

在布局文件中使用:

消息:

 <com.ezreal.ezchat.widget.ChangeColorIconWithText
                android:id="@+id/id_indicator_msg"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="5dp"
                app:color="@color/app_blue_color"
                app:icon="@mipmap/icon_msg"
                app:text="消息"
                app:text_size="12sp"/>

通讯录:

<com.ezreal.ezchat.widget.ChangeColorIconWithText
                android:id="@+id/id_indicator_contact"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:padding="5dp"
                app:color="@color/app_blue_color"
                app:icon="@mipmap/icon_contact"
                app:text="通讯录"
                app:text_size="12sp"/>
我:
<com.ezreal.ezchat.widget.ChangeColorIconWithText
                android:id="@+id/id_indicator_me"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:padding="5dp"
                app:color="@color/app_blue_color"
                app:icon="@mipmap/icon_me"
                app:text="我"
                app:text_size="12sp"/>
获取自定义属性:
/**
	 * 获取自定义属性的值
	 * 
	 * @param context 上下文
	 * @param attrs  自定义属性
	 * @param defStyleAttr  默认风格
	 */
	public ChangeColorIconWithText(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);

		TypedArray a = context.obtainStyledAttributes(attrs,
				R.styleable.ChangeColorIconWithText);

		int n = a.getIndexCount();

		for (int i = 0; i < n; i++)
		{
			int attr = a.getIndex(i);
			switch (attr)
			{
			case R.styleable.ChangeColorIconWithText_icon:
				BitmapDrawable drawable = (BitmapDrawable) a.getDrawable(attr);
				mIconBitmap = drawable.getBitmap();
				break;
			case R.styleable.ChangeColorIconWithText_color:
				mColor = a.getColor(attr, 0xFF60CAF1);
				break;
			case R.styleable.ChangeColorIconWithText_text:
				mText = a.getString(attr);
				break;
			case R.styleable.ChangeColorIconWithText_text_size:
				mTextSize = (int) a.getDimension(attr, TypedValue
						.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12,
								getResources().getDisplayMetrics()));
				break;
			}

		}

		a.recycle();

		mTextBound = new Rect();
		mTextPaint = new Paint();
		mTextPaint.setTextSize(mTextSize);
		mTextPaint.setColor(0Xffbfbfbf);
		mTextPaint.setAntiAlias(true); //设置抗锯齿
		mTextPaint.setDither(true);  //设置抖动
		mTextPaint.getTextBounds(mText, 0, mText.length(), mTextBound);

	}


2. 更改自定义view的绘制范围

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		//得到绘制icon的宽
		int iconWidth = Math.min(getMeasuredWidth() - getPaddingLeft()
				- getPaddingRight(), getMeasuredHeight() - getPaddingTop()
				- getPaddingBottom() - mTextBound.height());

		int left = getMeasuredWidth() / 2 - iconWidth / 2;
		int top = getMeasuredHeight() / 2 - (mTextBound.height() + iconWidth)
				/ 2;
		mIconRect = new Rect(left, top, left + iconWidth, top + iconWidth);//设置icon的绘制范围
	}

3. 绘制自定义view

  //先在内存中的Canvas上绘制一个可变色的bitmap,然后再将其绘制到屏幕显示的Canvas上
	//文字的变色和图标的变色都用相同的alpha来控制
	@Override
	protected void onDraw(Canvas canvas) {

		// 绘制原图
		canvas.drawBitmap(mIconBitmap, null, mIconRect, null);

		// 内存去准备变色的 mBitmap
		int alpha = (int) Math.ceil(255 * mAlpha);
		setupTargetBitmap(alpha);

		// 绘制原文本
		drawSourceText(canvas, alpha);

		// 绘制变色的文本
		drawTargetText(canvas, alpha);

		// 绘制渐变色后的图 mBitmap
		canvas.drawBitmap(mBitmap, 0, 0, null);
	}

	private void drawTargetText(Canvas canvas, int alpha) {
		mTextPaint.setColor(mColor);
		mTextPaint.setAlpha(alpha);
		int x = getMeasuredWidth() / 2 - mTextBound.width() / 2;
		int y = mIconRect.bottom + mTextBound.height();
		canvas.drawText(mText, x, y, mTextPaint);
	}

	private void drawSourceText(Canvas canvas, int alpha) {
		mTextPaint.setColor(0xffbfbfbf);
		mTextPaint.setAlpha(255 - alpha);
		int x = getMeasuredWidth() / 2 - mTextBound.width() / 2;
		int y = mIconRect.bottom + mTextBound.height();
		canvas.drawText(mText, x, y, mTextPaint);
	}

	/**
	 * 在内存中绘制可变色的Icon
	 */
	private void setupTargetBitmap(int alpha) {

		// 根据 view 大小生成空画布
		mBitmap = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(),
				Config.ARGB_8888);
		mCanvas = new Canvas(mBitmap);

		// 绘制纯色的带透明度的矩形,目标图像
		mPaint = new Paint();
		mPaint.setColor(mColor);
		mPaint.setAntiAlias(true);
		mPaint.setDither(true);
		mPaint.setAlpha(alpha);
		mCanvas.drawRect(mIconRect, mPaint);

		// DST_IN 只绘制目标图像,并且只绘制它和源图像重合的区域
		mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));

		// 把 mIcon(原图) 绘制上去,最终得到一个,由alpha决定颜色的 mIconBitmap
		mPaint.setAlpha(255);
		mCanvas.drawBitmap(mIconBitmap, null, mIconRect, mPaint);

	}


4. 控制icon变色(设置透明度)

public void setIconAlpha(float alpha) {
		this.mAlpha = alpha;
		invalidateView();
	}

	/**
	 * 重绘
	 */
	private void invalidateView() {
		if (Looper.getMainLooper() == Looper.myLooper()) {
			//判断是否是主线程
			invalidate();
		} else {
			postInvalidate();
		}
	}

}


二. 实现OnPageChangeListener中的方法

1. onPageScrolled

如果页面向右翻动,positionOffset不断变大(从0到1),则该ChangeColorIconWithText的左侧ChangecolorIconWithText的透明度不断减小,右边的不断增大,由此产生渐变颜色效果

@Override
    public void onPageScrolled(int position, float positionOffset,
                               int positionOffsetPixels) {
        if (positionOffset > 0) {
            //随手指滑动,下方图标可产生渐变颜色效果
            ChangeColorIconWithText left = mTabIndicators.get(position);
            ChangeColorIconWithText right = mTabIndicators.get(position + 1);
            left.setIconAlpha(1 - positionOffset);
            right.setIconAlpha(positionOffset);
        }
    }

2.onPageSelected

MSG_CHATTING_ACCOUNT_ALL:目前没有与任何人对话,但能看到消息提醒(在消息列表界面),不需要在状态栏做消息通知

MSG_CHATTING_ACCOUNT_NONE:目前没有与任何人对话,需要在状态栏做消息通知

 @Override
    public void onPageSelected(int position) {
        // 切换到最近联系人列表界面
        if (position == 0){
            // 能看到新消息提醒,不需要通知栏通知
            NIMClient.getService(MsgService.class)
                    .setChattingAccount(MsgService.MSG_CHATTING_ACCOUNT_ALL,
                            SessionTypeEnum.None);
        } else {
            // 不能看到消息提醒,需要通知栏通知
            NIMClient.getService(MsgService.class)
                    .setChattingAccount(MsgService.MSG_CHATTING_ACCOUNT_NONE,
                            SessionTypeEnum.None);
        }
    }



附上相关完整代码:

ChangeColorIconWithText.java

package com.ezreal.ezchat.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.os.Looper;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;

import com.ezreal.ezchat.R;

public class ChangeColorIconWithText extends View {

	private int mColor = 0xFF45C01A;
	private Bitmap mIconBitmap;
	private String mText = "消息";
	private int mTextSize = (int) TypedValue.applyDimension(
			TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics());

	private Canvas mCanvas;
	private Bitmap mBitmap;
	private Paint mPaint;

	private float mAlpha;

	private Rect mIconRect; //限制绘制icon的范围
	private Rect mTextBound;  //绘制时控制文本绘制的范围
	private Paint mTextPaint; //文字画笔

	public ChangeColorIconWithText(Context context) {
		this(context, null);
	}

	public ChangeColorIconWithText(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	/**
	 * 获取自定义属性的值
	 * 
	 * @param context 上下文
	 * @param attrs  自定义属性
	 * @param defStyleAttr  默认风格
	 */
	public ChangeColorIconWithText(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);

		TypedArray a = context.obtainStyledAttributes(attrs,
				R.styleable.ChangeColorIconWithText);

		int n = a.getIndexCount();

		for (int i = 0; i < n; i++)
		{
			int attr = a.getIndex(i);
			switch (attr)
			{
			case R.styleable.ChangeColorIconWithText_icon:
				BitmapDrawable drawable = (BitmapDrawable) a.getDrawable(attr);
				mIconBitmap = drawable.getBitmap();
				break;
			case R.styleable.ChangeColorIconWithText_color:
				mColor = a.getColor(attr, 0xFF60CAF1);
				break;
			case R.styleable.ChangeColorIconWithText_text:
				mText = a.getString(attr);
				break;
			case R.styleable.ChangeColorIconWithText_text_size:
				mTextSize = (int) a.getDimension(attr, TypedValue
						.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12,
								getResources().getDisplayMetrics()));
				break;
			}

		}

		a.recycle();

		mTextBound = new Rect();
		mTextPaint = new Paint();
		mTextPaint.setTextSize(mTextSize);
		mTextPaint.setColor(0Xffbfbfbf);
		mTextPaint.setAntiAlias(true); //设置抗锯齿
		mTextPaint.setDither(true);  //设置抖动
		mTextPaint.getTextBounds(mText, 0, mText.length(), mTextBound);

	}


	//确定图标位置
	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		//得到绘制icon的宽
		int iconWidth = Math.min(getMeasuredWidth() - getPaddingLeft()
				- getPaddingRight(), getMeasuredHeight() - getPaddingTop()
				- getPaddingBottom() - mTextBound.height());

		int left = getMeasuredWidth() / 2 - iconWidth / 2;
		int top = getMeasuredHeight() / 2 - (mTextBound.height() + iconWidth)
				/ 2;
		mIconRect = new Rect(left, top, left + iconWidth, top + iconWidth);//设置icon的绘制范围
	}


	//先在内存中的Canvas上绘制一个可变色的bitmap,然后再将其绘制到屏幕显示的Canvas上
	//文字的变色和图标的变色都用相同的alpha来控制
	@Override
	protected void onDraw(Canvas canvas) {

		// 绘制原图
		canvas.drawBitmap(mIconBitmap, null, mIconRect, null);

		// 内存去准备变色的 mBitmap
		int alpha = (int) Math.ceil(255 * mAlpha);
		setupTargetBitmap(alpha);

		// 绘制原文本
		drawSourceText(canvas, alpha);

		// 绘制变色的文本
		drawTargetText(canvas, alpha);

		// 绘制渐变色后的图 mBitmap
		canvas.drawBitmap(mBitmap, 0, 0, null);
	}

	private void drawTargetText(Canvas canvas, int alpha) {
		mTextPaint.setColor(mColor);
		mTextPaint.setAlpha(alpha);
		int x = getMeasuredWidth() / 2 - mTextBound.width() / 2;
		int y = mIconRect.bottom + mTextBound.height();
		canvas.drawText(mText, x, y, mTextPaint);
	}

	private void drawSourceText(Canvas canvas, int alpha) {
		mTextPaint.setColor(0xffbfbfbf);
		mTextPaint.setAlpha(255 - alpha);
		int x = getMeasuredWidth() / 2 - mTextBound.width() / 2;
		int y = mIconRect.bottom + mTextBound.height();
		canvas.drawText(mText, x, y, mTextPaint);
	}

	/**
	 * 在内存中绘制可变色的Icon
	 */
	private void setupTargetBitmap(int alpha) {

		// 根据 view 大小生成空画布
		mBitmap = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(),
				Config.ARGB_8888);
		mCanvas = new Canvas(mBitmap);

		// 绘制纯色的带透明度的矩形,目标图像
		mPaint = new Paint();
		mPaint.setColor(mColor);
		mPaint.setAntiAlias(true);
		mPaint.setDither(true);
		mPaint.setAlpha(alpha);
		mCanvas.drawRect(mIconRect, mPaint);

		// DST_IN 只绘制目标图像,并且只绘制它和源图像重合的区域
		mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));

		// 把 mIcon(原图) 绘制上去,最终得到一个,由alpha决定颜色的 mIconBitmap
		mPaint.setAlpha(255);
		mCanvas.drawBitmap(mIconBitmap, null, mIconRect, mPaint);

	}

	private static final String INSTANCE_STATUS = "instance_status";
	private static final String STATUS_ALPHA = "status_alpha";

	//在自定义view销毁之前,保存变量mAlpha的值
	@Override
	protected Parcelable onSaveInstanceState() {
		Bundle bundle = new Bundle();
		bundle.putParcelable(INSTANCE_STATUS, super.onSaveInstanceState());
		bundle.putFloat(STATUS_ALPHA, mAlpha);
		return bundle;
	}

	//在自定义view生成之前,提取之前保存的变量mAlpha的值
	@Override
	protected void onRestoreInstanceState(Parcelable state) {
		if (state instanceof Bundle) {
			Bundle bundle = (Bundle) state;
			mAlpha = bundle.getFloat(STATUS_ALPHA);
			super.onRestoreInstanceState(bundle.getParcelable(INSTANCE_STATUS));
			return;
		}
		super.onRestoreInstanceState(state);
	}

	public void setIconAlpha(float alpha) {
		this.mAlpha = alpha;
		invalidateView();
	}

	/**
	 * 重绘
	 */
	private void invalidateView() {
		if (Looper.getMainLooper() == Looper.myLooper()) {
			//判断是否是主线程
			invalidate();
		} else {
			postInvalidate();
		}
	}

}


MainActivity.java

package com.ezreal.ezchat.activity;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;

import com.ezreal.ezchat.R;
import com.ezreal.ezchat.fragment.BaseFragment;
import com.ezreal.ezchat.fragment.ContractFragment;
import com.ezreal.ezchat.fragment.MeFragment;
import com.ezreal.ezchat.fragment.RecentMsgFragment;
import com.ezreal.ezchat.handler.NimFriendHandler;
import com.ezreal.ezchat.handler.NimOnlineStatusHandler;
import com.ezreal.ezchat.handler.NimSysMsgHandler;
import com.ezreal.ezchat.handler.NimUserHandler;
import com.ezreal.ezchat.utils.ImageSQLiteHelper;
import com.ezreal.ezchat.widget.ChangeColorIconWithText;
import com.javonlee.dragpointview.view.DragPointView;
import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.NimIntent;
import com.netease.nimlib.sdk.msg.MsgService;
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
import com.netease.nimlib.sdk.msg.model.IMMessage;
import com.netease.nimlib.sdk.uinfo.UserService;
import com.netease.nimlib.sdk.uinfo.model.NimUserInfo;
import com.suntek.commonlibrary.utils.ToastUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.ezreal.ezchat.activity.CreateActivity.MY_COL;
import static com.ezreal.ezchat.activity.CreateActivity.MY_ROW;
import static com.ezreal.ezchat.activity.CreateActivity.myImageArrays;


public class MainActivity extends BaseActivity implements OnClickListener,
        OnPageChangeListener {

    static{
        System.loadLibrary("native-lib");
    }

    private static final String TAG = MainActivity.class.getSimpleName();

    @BindView(R.id.view_page)
    ViewPager mViewPager;
    @BindView(R.id.id_indicator_msg)
    ChangeColorIconWithText mIndicatorMsg;
    @BindView(R.id.id_indicator_contact)
    ChangeColorIconWithText mIndicatorContract;
    @BindView(R.id.id_indicator_me)
    ChangeColorIconWithText mIndicatorMe;
    @BindView(R.id.dpv_unread_recent_msg)
    DragPointView mDpvUnRead;

    private List<BaseFragment> mFragments;
    private List<ChangeColorIconWithText> mTabIndicators = new ArrayList<>();
    private RecentMsgFragment mMsgFragment;
    private ContractFragment mContractFragment;
    private MeFragment mMeFragment;
    private String[] imageStr;
    private int[][] myImageArray;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);//绘制界面
        setStatusBarColor(R.color.app_blue_color);
        setContentView(R.layout.activity_main);
        setTitleBar(getString(R.string.app_name),false,false);
        ButterKnife.bind(this);
        initView();
        bindFragment();
        initHandler();
        getImageArry();

        // 开启通知栏,有信息的时候通知
        NIMClient.toggleNotification(true);

        // 由通知栏点击进入后,用于跳转到指定的聊天界面
//        ArrayList<IMMessage> messages = (ArrayList<IMMessage>)
//                getIntent().getSerializableExtra(NimIntent.EXTRA_NOTIFY_CONTENT);
//        if (messages != null && !messages.isEmpty()){
//            IMMessage message = messages.get(0);
//            NimUserInfo userInfo = NIMClient.getService(UserService.class)
//                    .getUserInfo(message.getSessionId());
//            Intent intent = new Intent(this,P2PChatActivity.class);
//            intent.putExtra("NimUserInfo",userInfo);
//            startActivity(intent);
//        }

    }

    private void initView() {
        mTabIndicators.add(mIndicatorMsg);
        mTabIndicators.add(mIndicatorContract);
        mTabIndicators.add(mIndicatorMe);

        mIndicatorMsg.setOnClickListener(this);
        mIndicatorContract.setOnClickListener(this);
        mIndicatorMe.setOnClickListener(this);
        mIndicatorMsg.setIconAlpha(1.0f);
    }

    private void bindFragment() {
        mFragments = new ArrayList<>();
        mMsgFragment = new RecentMsgFragment();
        mFragments.add(mMsgFragment);
        mContractFragment = new ContractFragment();
        mFragments.add(mContractFragment);
        mMeFragment = new MeFragment();
        mFragments.add(mMeFragment);

        FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public int getCount() {
                return mFragments.size();
            }

            @Override
            public Fragment getItem(int position) {
                return mFragments.get(position);
            }
        };
        mViewPager.setAdapter(adapter);//设置适配器
        mViewPager.addOnPageChangeListener(this); //添加页面切换时的监听
    }

    private void initHandler() {
        NimOnlineStatusHandler.getInstance().init();
        NimOnlineStatusHandler.getInstance().setStatusChangeListener(
                new NimOnlineStatusHandler.OnStatusChangeListener() {
            @Override
            public void requestReLogin(String message) {
                ToastUtils.showMessage(MainActivity.this,"自动登陆失败或被踢出,请手动登陆~");
                startActivity(new Intent(MainActivity.this,LoginActivity.class));
            }

            @Override
            public void networkBroken() {

            }
        });

        NimSysMsgHandler.getInstance().init();
        NimFriendHandler.getInstance().init();
        NimUserHandler.getInstance().init();
    }

    @Override
    public void onClick(View v) {
        resetOtherTabs();
        switch (v.getId()) {
            case R.id.id_indicator_msg:
                mIndicatorMsg.setIconAlpha(1.0f);
                mViewPager.setCurrentItem(0, false); //去除mViewPager的滑动效果
                break;
            case R.id.id_indicator_contact:
                mIndicatorContract.setIconAlpha(1.0f);
                mViewPager.setCurrentItem(1, false);
                break;
            case R.id.id_indicator_me:
                mIndicatorMe.setIconAlpha(1.0f);
                mViewPager.setCurrentItem(2, false);
                break;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            Intent home = new Intent(Intent.ACTION_MAIN); //指定跳到系统桌面
            home.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // 清除上一步缓存
            home.addCategory(Intent.CATEGORY_HOME);
            startActivity(home); //开始跳转
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    private void resetOtherTabs() {
        for (int i = 0; i < mTabIndicators.size(); i++) {
            mTabIndicators.get(i).setIconAlpha(0);
        }
    }

    @Override
    public void onPageScrolled(int position, float positionOffset,
                               int positionOffsetPixels) {
        if (positionOffset > 0) {
            //随手指滑动,下方图标可产生渐变颜色效果
            ChangeColorIconWithText left = mTabIndicators.get(position);
            ChangeColorIconWithText right = mTabIndicators.get(position + 1);
            left.setIconAlpha(1 - positionOffset);
            right.setIconAlpha(positionOffset);
        }
    }

    @Override
    public void onPageSelected(int position) {
        // 切换到最近联系人列表界面
        if (position == 0){
            // 能看到新消息提醒,不需要通知栏通知
            NIMClient.getService(MsgService.class)
                    .setChattingAccount(MsgService.MSG_CHATTING_ACCOUNT_ALL,
                            SessionTypeEnum.None);
        } else {
            // 不能看到消息提醒,需要通知栏通知
            NIMClient.getService(MsgService.class)
                    .setChattingAccount(MsgService.MSG_CHATTING_ACCOUNT_NONE,
                            SessionTypeEnum.None);
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

activity_main.xml

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <include layout="@layout/title_layout"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/view_page"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="45dp"
        android:orientation="horizontal">

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <com.ezreal.ezchat.widget.ChangeColorIconWithText
                android:id="@+id/id_indicator_msg"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="5dp"
                app:color="@color/app_blue_color"
                app:icon="@mipmap/icon_msg"
                app:text="消息"
                app:text_size="12sp"/>

            <com.javonlee.dragpointview.view.DragPointView
                android:id="@+id/dpv_unread_recent_msg"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/shape_drag_point_red"
                android:gravity="center"
                android:text="1"
                android:textColor="@color/white_color"
                android:textSize="14sp"
                android:visibility="gone"
                app:centerMinRatio="0.5"
                app:colorStretching="@color/app_red_color"
                app:dragCircleRadius="50dp"
                app:maxDragLength="100dp"
                app:recoveryAnimBounce="0.25"
                android:layout_alignParentTop="true"
                android:layout_marginRight="5dp"
                android:layout_marginTop="5dp"
                android:layout_alignParentRight="true"/>

        </RelativeLayout>

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <com.ezreal.ezchat.widget.ChangeColorIconWithText
                android:id="@+id/id_indicator_contact"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:padding="5dp"
                app:color="@color/app_blue_color"
                app:icon="@mipmap/icon_contact"
                app:text="通讯录"
                app:text_size="12sp"/>

        </RelativeLayout>


        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:visibility="gone">

            <com.ezreal.ezchat.widget.ChangeColorIconWithText
                android:id="@+id/id_indicator_found"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:padding="5dp"
                app:color="@color/app_blue_color"
                app:icon="@mipmap/icon_found"
                app:text="发现"
                app:text_size="12sp"/>

            <ImageView
                android:id="@+id/dpv_found_new_msg"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_marginRight="15dp"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:scaleType="fitXY"
                android:src="@mipmap/point"
                android:visibility="gone"/>

        </RelativeLayout>


        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">

            <com.ezreal.ezchat.widget.ChangeColorIconWithText
                android:id="@+id/id_indicator_me"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:padding="5dp"
                app:color="@color/app_blue_color"
                app:icon="@mipmap/icon_me"
                app:text="我"
                app:text_size="12sp"/>

        </RelativeLayout>

    </LinearLayout>

</LinearLayout>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值