Skip to content

Commit

Permalink
新增SuperTextView的简化版CommonTtextView
Browse files Browse the repository at this point in the history
  • Loading branch information
lygttpod committed Nov 24, 2016
1 parent fef98a7 commit 3a42cc2
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 126 deletions.
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
</activity>
<activity android:name=".TypeActivity"/>
<activity android:name=".ListActivity"/>
<activity android:name=".CommonTextViewActivity"/>
<activity android:name=".CommonTextViewActivity"
android:label="CommonTextView"/>
</application>

</manifest>
10 changes: 9 additions & 1 deletion app/src/main/java/com/allen/supertextview/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe

private Drawable drawable;

private Button button0,button1,button2,button3,button4,button5,button6;
private Button button0,button1,button2,button3,button4,button5,button6,button7;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -28,6 +28,7 @@ protected void onCreate(Bundle savedInstanceState) {
button4 = (Button) findViewById(R.id.button4);
button5 = (Button) findViewById(R.id.button5);
button6 = (Button) findViewById(R.id.button6);
button7 = (Button) findViewById(R.id.button7);

button0.setOnClickListener(this);
button1.setOnClickListener(this);
Expand All @@ -36,6 +37,7 @@ protected void onCreate(Bundle savedInstanceState) {
button4.setOnClickListener(this);
button5.setOnClickListener(this);
button6.setOnClickListener(this);
button7.setOnClickListener(this);
}

@Override
Expand Down Expand Up @@ -73,6 +75,12 @@ public void onClick(View v) {
startActivity(intent);
break;
case R.id.button6:
// intent.setClass(this, ListActivity.class);
intent.setClass(this,TypeActivity.class);
intent.putExtra("type", 6);
startActivity(intent);
break;
case R.id.button7:
// intent.setClass(this, ListActivity.class);
intent.setClass(this, CommonTextViewActivity.class);
intent.putExtra("type", 6);
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="组合6" />
<Button
android:id="@+id/button7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CommonTextView" />
</LinearLayout>
</ScrollView>

Expand Down
45 changes: 44 additions & 1 deletion app/src/main/res/layout/common_textview_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@
ctv:cRightTextString="T+1日" />

<com.allen.library.CommonTextView
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="50dp"
ctv:cLeftIconResForDrawableLeft="@drawable/scatter_time"
ctv:cLeftTextString="起息时间"
ctv:cRightTextString="T+1日"
ctv:cRightIconResForDrawableRight="@drawable/arrow_right_red"/>

<com.allen.library.CommonTextView
android:layout_width="match_parent"
android:layout_height="50dp"
ctv:cCenterIconResForDrawableTop="@drawable/scatter_use"
Expand All @@ -57,5 +64,41 @@
ctv:cRightIconResForDrawableTop="@drawable/scatter_type"
ctv:cRightTextString="截至日期" />

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

<com.allen.library.CommonTextView
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
ctv:cCenterIconResForDrawableTop="@mipmap/ic_launcher"
ctv:cCenterTextColor="@color/colorAccent"
ctv:cCenterTextSize="15dp"
ctv:cUseRipple="true"

ctv:cCenterTextString="帐号管理" />

<com.allen.library.CommonTextView
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
ctv:cCenterIconResForDrawableTop="@mipmap/ic_launcher"
ctv:cCenterTextColor="@color/colorAccent"
ctv:cCenterTextSize="15dp"
ctv:cUseRipple="true"

ctv:cCenterTextString="帐号管理" />

<com.allen.library.CommonTextView
android:layout_width="0dp"
android:layout_height="100dp"
ctv:cUseRipple="true"
android:layout_weight="1"
ctv:cCenterIconResForDrawableTop="@mipmap/ic_launcher"
ctv:cCenterTextColor="@color/colorAccent"
ctv:cCenterTextSize="15dp"
ctv:cCenterTextString="帐号管理" />
</LinearLayout>
</LinearLayout>
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
defaultConfig {
minSdkVersion 11
targetSdkVersion 24
versionCode 105
versionName "1.0.5"
versionCode 106
versionName "1.0.6"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
40 changes: 26 additions & 14 deletions library/src/main/java/com/allen/library/CommonTextView.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
Expand Down Expand Up @@ -96,11 +97,9 @@ public class CommonTextView extends RelativeLayout {
*/
private boolean useRipple;

private static final int DRAWABLE_LEFT = 11;
private static final int DRAWABLE_TOP = 12;
private static final int DRAWABLE_RIGHT = 13;
private static final int DRAWABLE_BOTTOM = 14;

private boolean mSetSingleLine = true;
private int mSetMaxEms = 10;
private int mSetLines = 1;

private TextView leftTextView, centerTextView, rightTextView;

Expand All @@ -110,6 +109,7 @@ public class CommonTextView extends RelativeLayout {

private OnCommonTextViewClickListener onCommonTextViewClickListener;


public CommonTextView(Context context) {
this(context, null);
}
Expand Down Expand Up @@ -190,6 +190,11 @@ private void getAttr(AttributeSet attrs) {
useRipple = typedArray.getBoolean(R.styleable.CommonTextView_cUseRipple, false);

mBackgroundColor = typedArray.getColor(R.styleable.CommonTextView_cBackgroundColor, mBackgroundColor);

mSetSingleLine = typedArray.getBoolean(R.styleable.CommonTextView_cSetSingleLine, true);
mSetMaxEms = typedArray.getInt(R.styleable.CommonTextView_cSetMaxEms, mSetMaxEms);
mSetLines = typedArray.getInt(R.styleable.CommonTextView_cSetLines, 1);

typedArray.recycle();
}

Expand All @@ -199,9 +204,15 @@ private void getAttr(AttributeSet attrs) {
private void init() {
initCommonTextView();
initLineView();
initLeftText();
initCenterText();
initRightText();
if (mLeftTextString != null) {
initLeftText();
}
if (mCenterTextString != null) {
initCenterText();
}
if (mRightTextString != null) {
initRightText();
}
}

/**
Expand Down Expand Up @@ -293,10 +304,11 @@ private void initLeftText() {
}
leftTVParams.addRule(CENTER_VERTICAL, TRUE);
leftTVParams.addRule(ALIGN_PARENT_LEFT, TRUE);
// leftTVParams.addRule(LEFT_OF, R.id.cRightTextId);
leftTVParams.setMargins(mLeftViewPaddingLeft, 0, mLeftViewPaddingRight, 0);
leftTextView = initText(leftTextView, leftTVParams, R.id.cLeftTextId, mLeftTextColor, mLeftTextSize);
leftTextView.setText(mLeftTextString);
leftTextView.setGravity(Gravity.CENTER_VERTICAL);
// leftTextView.setGravity(Gravity.CENTER_VERTICAL);
leftTextView.setLineSpacing(mLeftTextViewLineSpacingExtra, 1.0f);
}

Expand All @@ -319,7 +331,6 @@ private void initCenterText() {

centerTextView = initText(centerTextView, centerTVParams, R.id.cCenterTextId, mCenterTextColor, mCenterTextSize);
centerTextView.setText(mCenterTextString);
centerTextView.setGravity(Gravity.CENTER);
centerTextView.setLineSpacing(mCenterTextViewLineSpacingExtra, 1.0f);

}
Expand All @@ -339,10 +350,9 @@ private void initRightText() {
rightTVParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE);
rightTVParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, TRUE);
rightTVParams.setMargins(mRightViewPaddingLeft, 0, mRightViewPaddingRight, 0);

rightTextView = initText(rightTextView, rightTVParams, R.id.cRightTextId, mRightTextColor, mRightTextSize);
rightTextView.setText(mRightTextString);
rightTextView.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
// rightTextView.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT);
rightTextView.setLineSpacing(mRightTextViewLineSpacingExtra, 1.0f);

}
Expand Down Expand Up @@ -382,8 +392,10 @@ public TextView initText(TextView textView, LayoutParams layoutParams, int id, i
textView.setTextColor(textColor);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
textView.setGravity(Gravity.CENTER);
textView.setLines(1);
textView.setEms(10);
textView.setLines(mSetLines);
textView.setSingleLine(mSetSingleLine);
textView.setMaxEms(mSetMaxEms);
textView.setEllipsize(TextUtils.TruncateAt.END);
addView(textView);
}
return textView;
Expand Down
Loading

0 comments on commit 3a42cc2

Please sign in to comment.