package com.basic.security.utils;
|
|
import android.content.Context;
|
import android.util.AttributeSet;
|
import android.widget.LinearLayout;
|
import android.widget.TextView;
|
|
public class InfoTextView extends LinearLayout {
|
|
|
private Context mContext;
|
private TextView mLeftTextView, mRightTextView;
|
private String mLeftTextString, mRightTextString;
|
private int mBetweenMargin, mLeftTextSize, mRightTextSize, mLeftTextColor, mRightTextColor, mBackgroundColor;
|
private int mDefaultMargin = 0;
|
private int mDefaultTextSize = 0;
|
private int mDefaultTextColor = 0xff515b64;
|
private int mDefaultBackgroundColor = 0xffffffff;
|
private LayoutParams mLeftLayoutParams, mRightLayoutParams;
|
|
public InfoTextView(Context context) {
|
super(context);
|
}
|
|
public InfoTextView(Context context, AttributeSet attrs) {
|
super(context, attrs);
|
getAttr(attrs);
|
initLayout();
|
}
|
|
|
/**
|
* 初始化布局
|
*/
|
private void initLayout() {
|
this.setBackgroundColor(mBackgroundColor);
|
this.setOrientation(HORIZONTAL);
|
initLeftText();
|
initRightText();
|
}
|
|
/**
|
* 获取定义属性值
|
*
|
* @param attrs
|
*/
|
private void getAttr(AttributeSet attrs) {
|
// TypedArray typedArray = mContext.obtainStyledAttributes(attrs, R.styleable.VisitorView);
|
// mLeftTextString = typedArray.getString(R.styleable.VisitorView_vLeftTextString);
|
// mRightTextString = typedArray.getString(R.styleable.VisitorView_vRightTextString);
|
// mBetweenMargin = typedArray.getDimensionPixelSize(R.styleable.VisitorView_vBetweenMargin,mDefaultMargin);
|
// mLeftTextSize = typedArray.getDimensionPixelSize(R.styleable.VisitorView_vLeftTextSize,mDefaultTextSize);
|
// mRightTextSize = typedArray.getDimensionPixelSize(R.styleable.VisitorView_vRightTextSize,mDefaultTextSize);
|
// mLeftTextColor = typedArray.getColor(R.styleable.VisitorView_vLeftTextColor,mDefaultTextColor);
|
// mRightTextColor = typedArray.getColor(R.styleable.VisitorView_vRightTextColor,mDefaultTextColor);
|
// mBackgroundColor = typedArray.getColor(R.styleable.VisitorView_vBackgroundColor,mDefaultBackgroundColor);
|
// typedArray.recycle();
|
}
|
|
/**
|
* 初始化左边文字
|
*/
|
private void initLeftText() {
|
mLeftTextView = new TextView(mContext);
|
mLeftLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
mLeftTextView.setLayoutParams(mLeftLayoutParams);
|
mLeftTextView.setText(mLeftTextString);
|
setTextColor(mLeftTextView, mLeftTextColor);
|
setTextSize(mLeftTextView, mLeftTextSize);
|
addView(mLeftTextView);
|
}
|
|
/**
|
* 初始化右边文字
|
*/
|
private void initRightText() {
|
mRightTextView = new TextView(mContext);
|
mRightLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
mRightTextView.setLayoutParams(mRightLayoutParams);
|
mRightTextView.setText(mRightTextString);
|
setTextColor(mRightTextView, mRightTextColor);
|
setTextSize(mRightTextView, mRightTextSize);
|
addView(mRightTextView);
|
}
|
|
|
/**
|
* 设置字体颜色
|
*
|
* @param textView textview对象
|
* @param color 文字颜色
|
*/
|
private void setTextColor(TextView textView, int color) {
|
textView.setTextColor(color);
|
}
|
|
/**
|
* 设置字体大小
|
*
|
* @param textView textview对象
|
* @param size 文字大小
|
*/
|
private void setTextSize(TextView textView, int size) {
|
textView.setTextSize(size);
|
}
|
}
|