Skip to content

Commit

Permalink
Merge pull request #11 from fuyuguang/master
Browse files Browse the repository at this point in the history
增加一种条目样式
  • Loading branch information
lygttpod authored Nov 18, 2016
2 parents b0c267e + 4389a7a commit 426604d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
13 changes: 13 additions & 0 deletions app/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@
stv:sLeftTextString="设置中心"
stv:sRightIconRes="@drawable/arrow_right_red" />


<com.allen.library.SuperTextView
android:layout_width="match_parent"
android:layout_height="50dp"
stv:sLeftTextString="客服热线"
stv:sRightTextColor="#ff0000"
stv:sRightTextSize="12dp"
stv:sLeftTextSize="14dip"
stv:sRightTextStringRightIconRes="@drawable/arrow_right_red"
stv:sRightTextStringRightIconResPadding="8dip"
stv:sRightTextString="4006179999"
stv:sUseRipple="true" />

<com.allen.library.SuperTextView
android:layout_width="match_parent"
android:layout_height="50dp"
Expand Down
36 changes: 35 additions & 1 deletion library/src/main/java/com/allen/library/SuperTextView.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public class SuperTextView extends RelativeLayout {
leftBottomParams2, rightTextParams, rightImgParams, rightCheckBoxParams;

private OnSuperTextViewClickListener onSuperTextViewClickListener;
private Drawable rightTextStringRightIconRes;
private int rightTextStringRightIconPadding;


public SuperTextView(Context context) {
Expand Down Expand Up @@ -151,6 +153,9 @@ private void getAttr(AttributeSet attrs) {
centerTextString = typedArray.getString(R.styleable.SuperTextView_sCenterTextString);
rightTextString = typedArray.getString(R.styleable.SuperTextView_sRightTextString);

rightTextStringRightIconRes = typedArray.getDrawable(R.styleable.SuperTextView_sRightTextStringRightIconRes);
rightTextStringRightIconPadding = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sRightTextStringRightIconResPadding,dip2px(mContext,5));

leftTopTextString = typedArray.getString(R.styleable.SuperTextView_sLeftTopTextString);
leftBottomTextString = typedArray.getString(R.styleable.SuperTextView_sLeftBottomTextString);
leftBottomTextString2 = typedArray.getString(R.styleable.SuperTextView_sLeftBottomTextString2);
Expand Down Expand Up @@ -227,7 +232,7 @@ private void initLayout() {
if (rightIconRes != null) {
initRightIcon();
}
if (rightTextString != null) {
if (rightTextString != null || rightTextStringRightIconRes != null) {
initRightText();
}
if (showCheckBox) {
Expand Down Expand Up @@ -475,6 +480,7 @@ private void initRightText() {
rightTV.setText(rightTextString);
setTextColor(rightTV, rightTVColor);
setTextSize(rightTV, rightTVSize);
setTextViewRightDrawble(rightTV,rightTextStringRightIconRes,rightTextStringRightIconPadding);
rightTV.setGravity(Gravity.RIGHT);
setTextViewParams(rightTV, isSingLines, maxLines, maxEms);
addView(rightTV);
Expand Down Expand Up @@ -669,6 +675,26 @@ public SuperTextView setRightString(String rightString) {
return this;
}

/**
* 设置右边显示的文字和图片
* @param rightString 右边文字
* @param drawable drawable
* @param drawablePadding drawablePadding
* @return
*/
public SuperTextView setRightString(String rightString,Drawable drawable,int drawablePadding) {
rightTextString = rightString;
rightTextStringRightIconRes = drawable;
rightTextStringRightIconPadding = drawablePadding;
if (rightTV == null) {
initRightText();
} else {
rightTV.setText(rightString);
}
return this;
}


/**
* 设备中间文字
*
Expand Down Expand Up @@ -940,4 +966,12 @@ public int sp2px(Context context, float spValue) {
final float scale = context.getResources().getDisplayMetrics().scaledDensity;
return (int) (spValue * scale + 0.5f);
}

public static void setTextViewRightDrawble(TextView textView,Drawable drawable,int drawablePadding){
if (drawable != null && textView != null) {
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
textView.setCompoundDrawables(null, null, drawable, null);
textView.setCompoundDrawablePadding(drawablePadding);
}
}
}
3 changes: 3 additions & 0 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<attr name="sLeftBottomTextMarginLeft" format="dimension"/>
<attr name="sLeftBottomTextMarginLeft2" format="dimension"/>

<attr name="sRightTextStringRightIconRes" format="reference"/>
<attr name="sRightTextStringRightIconResPadding" format="dimension"/>

<attr name="sRightIconMarginRight" format="dimension"/>
<attr name="sRightTextMarginRight" format="dimension"/>
<attr name="sRightCheckBoxMarginRight" format="dimension"/>
Expand Down

0 comments on commit 426604d

Please sign in to comment.