-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#1) code 添加图文组合控件TSCombinationButton
- Loading branch information
1 parent
27a1e61
commit fcf98e9
Showing
11 changed files
with
343 additions
and
0 deletions.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
tsui/src/main/java/com/zhiyicx/tsui/button/TSCombinationButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package com.zhiyicx.tsui.button; | ||
|
||
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.graphics.drawable.Drawable; | ||
import android.text.TextUtils; | ||
import android.util.AttributeSet; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.widget.FrameLayout; | ||
import android.widget.ImageView; | ||
import android.widget.RelativeLayout; | ||
import android.widget.TextView; | ||
|
||
import com.zhiyicx.tsui.R; | ||
import com.zhiyicx.tsui.utils.ConvertUtils; | ||
|
||
|
||
/** | ||
* @author LiuChao | ||
* @describe 个人中心的组合控件,图片-文字-图片 | ||
* @date 2017/1/7 | ||
* @contactemail:[email protected] | ||
*/ | ||
public class TSCombinationButton extends FrameLayout { | ||
ImageView mCombinedButtonImgLeft; | ||
ImageView mCombinedButtonImgRight; | ||
|
||
TextView mCombinedButtonLeftText; | ||
TextView mCombinedButtonRightText; | ||
View mVLine; | ||
|
||
public TSCombinationButton(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
LayoutInflater.from(context).inflate(R.layout.view_combination_button, this); | ||
mCombinedButtonImgLeft = (ImageView) findViewById(R.id.iv_left_img); | ||
mCombinedButtonImgRight = (ImageView) findViewById(R.id.iv_right_img); | ||
mCombinedButtonLeftText = (TextView) findViewById(R.id.tv_left_text); | ||
mCombinedButtonRightText = (TextView) findViewById(R.id.tv_right_text); | ||
mVLine = findViewById(R.id.v_line); | ||
TypedArray array = context.obtainStyledAttributes(attrs, | ||
R.styleable.tsCombinationBtn); | ||
Drawable leftImage = array.getDrawable(R.styleable.tsCombinationBtn_tsLeftImage); | ||
Drawable rightImage = array.getDrawable(R.styleable.tsCombinationBtn_tsRightImage); | ||
String leftText = array.getString(R.styleable.tsCombinationBtn_tsLeftText); | ||
String rightText = array.getString(R.styleable.tsCombinationBtn_tsRightText); | ||
int leftTextColor = array.getColor(R.styleable.tsCombinationBtn_tsLeftTextColor, -1); | ||
int rightTextColor = array.getColor(R.styleable.tsCombinationBtn_tsRightTextColor, -1); | ||
boolean showLine = array.getBoolean(R.styleable.tsCombinationBtn_tsShowLine, true); | ||
int dividerLeftMargin = array.getDimensionPixelSize(R.styleable.tsCombinationBtn_tsDividerLeftMargin, 0); | ||
int dividerRightMargin = array.getDimensionPixelSize(R.styleable.tsCombinationBtn_tsDividerRightMargin, 0); | ||
int leftTextLeftPadding = array.getDimensionPixelOffset(R.styleable.tsCombinationBtn_tsLeftTextLeftPadding, ConvertUtils.dp2px(context, 10)); | ||
array.recycle(); | ||
if (!TextUtils.isEmpty(leftText)) { | ||
mCombinedButtonLeftText.setText(leftText); | ||
} | ||
if (leftTextColor != -1) { | ||
mCombinedButtonLeftText.setTextColor(leftTextColor); | ||
} | ||
if (rightTextColor != -1) { | ||
mCombinedButtonRightText.setTextColor(rightTextColor); | ||
} | ||
if (!TextUtils.isEmpty(rightText)) { | ||
mCombinedButtonRightText.setText(rightText); | ||
} | ||
mCombinedButtonLeftText.setPadding(leftTextLeftPadding, 0, 0, 0); | ||
if (leftImage == null) { | ||
mCombinedButtonImgLeft.setVisibility(GONE); | ||
} else { | ||
mCombinedButtonImgLeft.setVisibility(VISIBLE); | ||
mCombinedButtonImgLeft.setImageDrawable(leftImage); | ||
} | ||
mCombinedButtonImgRight.setImageDrawable(rightImage); | ||
if (showLine) { | ||
mVLine.setVisibility(VISIBLE); | ||
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mVLine.getLayoutParams(); | ||
layoutParams.setMargins(dividerLeftMargin, 0, dividerRightMargin, 0); | ||
} else { | ||
mVLine.setVisibility(INVISIBLE); | ||
} | ||
} | ||
|
||
/** | ||
* 设置左边文字内容 | ||
*/ | ||
public void setLeftText(String leftText) { | ||
mCombinedButtonLeftText.setText(leftText); | ||
} | ||
|
||
/** | ||
* 设置右边文字内容 | ||
*/ | ||
public void setRightText(String rightText) { | ||
mCombinedButtonRightText.setText(rightText); | ||
} | ||
|
||
/** | ||
* 设置右边文字内容颜色 | ||
*/ | ||
public void setRightTextColor(int color) { | ||
mCombinedButtonRightText.setTextColor(color); | ||
} | ||
|
||
public TextView getCombinedButtonRightTextView() { | ||
return mCombinedButtonRightText; | ||
} | ||
|
||
public String getRightText() { | ||
return mCombinedButtonRightText.getText().toString(); | ||
} | ||
|
||
public void setRightImageClickListener(OnClickListener listener) { | ||
mCombinedButtonImgRight.setOnClickListener(listener); | ||
} | ||
|
||
public ImageView getCombinedButtonImgRight() { | ||
return mCombinedButtonImgRight; | ||
} | ||
|
||
public void setRightImage(int res) { | ||
mCombinedButtonImgRight.setImageResource(res); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
tsui/src/main/java/com/zhiyicx/tsui/utils/ConvertUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.zhiyicx.tsui.utils; | ||
|
||
import android.content.Context; | ||
|
||
/** | ||
* @Describe 转换相关工具类 | ||
* @Author Jungle68 | ||
* @Date 2016/12/15 | ||
* @Contact [email protected] | ||
*/ | ||
|
||
public class ConvertUtils { | ||
|
||
private ConvertUtils() { | ||
throw new UnsupportedOperationException("u can't instantiate me..."); | ||
} | ||
|
||
/** | ||
* dp 转 px | ||
* | ||
* @param dpValue dp值 | ||
* @return px值 | ||
*/ | ||
public static int dp2px(Context context, float dpValue) { | ||
final float scale = context.getResources().getDisplayMetrics().density; | ||
return (int) (dpValue * scale + 0.5f); | ||
} | ||
|
||
/** | ||
* px 转 dp | ||
* | ||
* @param pxValue px值 | ||
* @return dp值 | ||
*/ | ||
public static int px2dp(Context context, float pxValue) { | ||
final float scale = context.getResources().getDisplayMetrics().density; | ||
return (int) (pxValue / scale + 0.5f); | ||
} | ||
|
||
/** | ||
* sp 转 px | ||
* | ||
* @param spValue sp值 | ||
* @return px值 | ||
*/ | ||
public static int sp2px(Context context, float spValue) { | ||
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; | ||
return (int) (spValue * fontScale + 0.5f); | ||
} | ||
|
||
/** | ||
* px 转 sp | ||
* | ||
* @param pxValue px值 | ||
* @return sp值 | ||
*/ | ||
public static int px2sp(Context context, float pxValue) { | ||
final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; | ||
return (int) (pxValue / fontScale + 0.5f); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:oneshot="false" > | ||
|
||
<item | ||
android:drawable="@mipmap/default_white000" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@mipmap/default_white0001" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@mipmap/default_white0002" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@mipmap/default_white0003" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@mipmap/default_white0004" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@mipmap/default_white0005" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@mipmap/default_white0006" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@mipmap/default_white0007" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@mipmap/default_white0008" | ||
android:duration="100"/> | ||
<item | ||
android:drawable="@mipmap/default_white0009" | ||
android:duration="100"/> | ||
</animation-list> |
7 changes: 7 additions & 0 deletions
7
tsui/src/main/res/drawable/selector_button_corner_solid_big.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:drawable="@drawable/shape_button_corner_disable_solid_big" android:state_enabled="false"/> | ||
<item android:drawable="@drawable/shape_button_corner_press_solid_big" android:state_pressed="true"/> | ||
<item android:drawable="@drawable/shape_button_corner_normal_solid_big"/> | ||
</selector> | ||
|
10 changes: 10 additions & 0 deletions
10
tsui/src/main/res/drawable/shape_button_corner_disable_solid_big.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle" > | ||
|
||
<!-- 纯色 --> | ||
<solid android:color="@color/tsui_general_for_hint" /> | ||
<corners | ||
android:radius="@dimen/tsui_radius_4"/> | ||
|
||
</shape> |
9 changes: 9 additions & 0 deletions
9
tsui/src/main/res/drawable/shape_button_corner_disable_solid_small.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle" > | ||
|
||
<!-- 纯色 --> | ||
<solid android:color="@color/tsui_general_for_hint" /> | ||
<corners android:radius="@dimen/tsui_radius_2"/> | ||
|
||
</shape> |
10 changes: 10 additions & 0 deletions
10
tsui/src/main/res/drawable/shape_button_corner_normal_solid_big.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle" > | ||
|
||
<!-- 纯色 --> | ||
<solid android:color="@color/tsui_default_color" /> | ||
<corners | ||
android:radius="@dimen/tsui_radius_4"/> | ||
|
||
</shape> |
10 changes: 10 additions & 0 deletions
10
tsui/src/main/res/drawable/shape_button_corner_normal_solid_small.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle" > | ||
|
||
<!-- 纯色 --> | ||
<solid android:color="@color/tsui_default_color" /> | ||
<corners | ||
android:radius="@dimen/tsui_radius_2"/> | ||
|
||
</shape> |
10 changes: 10 additions & 0 deletions
10
tsui/src/main/res/drawable/shape_button_corner_press_solid_big.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle" > | ||
|
||
<!-- 纯色 --> | ||
<solid android:color="@color/tsui_default_pressed_color" /> | ||
<corners | ||
android:radius="@dimen/tsui_radius_4"/> | ||
|
||
</shape> |
10 changes: 10 additions & 0 deletions
10
tsui/src/main/res/drawable/shape_button_corner_press_solid_small.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle" > | ||
|
||
<!-- 纯色 --> | ||
<solid android:color="@color/tsui_default_pressed_color" /> | ||
<corners | ||
android:radius="@dimen/tsui_radius_4"/> | ||
|
||
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:skin="http://schemas.android.com/android/skin" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
tools:ignore="MissingPrefix" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="@color/tsui_config_color_white"> | ||
|
||
<ImageView | ||
android:id="@+id/iv_left_img" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerVertical="true" | ||
android:layout_marginLeft="@dimen/tsui_default_15"/> | ||
|
||
<TextView | ||
android:id="@+id/tv_left_text" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerVertical="true" | ||
android:paddingLeft="@dimen/tsui_default_10" | ||
android:layout_toRightOf="@id/iv_left_img" | ||
android:textColor="@color/tsui_default_color" | ||
android:textSize="@dimen/tsui_btn_text_size" | ||
skin:enable="true" | ||
tools:text="我的订阅" | ||
/> | ||
|
||
<ImageView | ||
android:id="@+id/iv_right_img" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentRight="true" | ||
android:layout_centerVertical="true" | ||
android:layout_marginRight="@dimen/tsui_default_15"/> | ||
|
||
<TextView | ||
android:id="@+id/tv_right_text" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:paddingRight="@dimen/tsui_default_15" | ||
android:textColor="@color/tsui_default_color" | ||
android:textSize="@dimen/tsui_btn_text_size" | ||
tools:text="34.8M" | ||
android:layout_marginRight="@dimen/tsui_default_10" | ||
android:layout_centerVertical="true" | ||
android:layout_toLeftOf="@+id/iv_right_img" | ||
android:layout_toStartOf="@+id/iv_right_img"/> | ||
|
||
<View | ||
android:id="@+id/v_line" | ||
style="@style/style_divider_horizontal_light" | ||
android:layout_alignParentBottom="true"/> | ||
</RelativeLayout> | ||
|