diff --git a/README.md b/README.md index 8c1b684..978ee4c 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,7 @@ - 3.2.1、布局中使用 - 3.2.2、在代码中使用 - 3.2.3、属性介绍 -* 4、 实现原理 - - 4.1、需求分析 - - 4.2、代码封装 - - 4.3、总结 -* 5、更新日志 +* 4、更新日志 ## 1、功能描述 > [**SuperTextView**](https://github.com/lygttpod/SuperTextView)是一个功能强大的View,可以满足日常大部分布局样式,开发者可已自行组合属性配置出属于自己风格的样式!可能描述起来没有概念,还是直接看效果图吧! @@ -50,27 +46,27 @@ ``` dependencies { ... - compile 'com.github.lygttpod:SuperTextView:1.1.2' + compile 'com.github.lygttpod:SuperTextView:2.0.0' } ``` ### 3.2、项目中如何使用 ##### 3.2.1、布局中如何使用(示例中只列出部分属性,开发者可根据具体需求使用其他属性) ``` -         +         注意: -                1、上下的线可以通过   sLineShow 设置  有四种显示方式 none,top,bottom,both +                1、上下的线可以通过   sDividerLineType 设置  有四种显示方式 none,top,bottom,both                 2、通过设置 sUseRipple=true 开启水波效果 ``` ##### 3.2.2、代码中如何使用 @@ -78,63 +74,107 @@        /**      * 可以通过链式设置大部分常用的属性值      */ -        superTextView.setLeftIcon(drawable) -                .setLeftString("") -                .setLeftTVColor(0) -                .setLeftTopString("") -                .setLeftTopTVColor(0) -                .setLeftBottomString("") -                .setLeftBottomTVColor(0) -                .setLeftBottomString2("") -                .setLeftBottomTVColor2(0) -                .setRightString("") -                .setRightTVColor(0) -                .setCbChecked(true) -                .setCbBackground(drawable) -                .setRightIcon(drawable) -                .setRightString("") -                .setRightTVColor(0) -                .setLeftString("") -``` -###### 点击事件(可根据需求选择实现单个或者多个点击事件,需要配合xml添加是否允许点击的属性,详情见属性参数的意义) -``` -        superTextView.setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener() { -                    @Override -                    public void onSuperTextViewClick() { -                        super.onSuperTextViewClick(); -                        //do something -                    } - -                    @Override -                    public void onLeftTopClick() { -                        super.onLeftTopClick(); -                        //do something -                    } - -                    @Override -                    public void onLeftBottomClick() { -                        super.onLeftBottomClick(); -                        //do something -                    } - -                    @Override -                    public void onLeftBottomClick2() { -                        super.onLeftBottomClick2(); -                        //do something -                    } -                }); - - 注意:点击事件需要配合属性值使用 - sLeftTopViewIsClickable= true - sLeftBottomViewIsClickable= true - sLeftBottomView2IsClickable= true +  superTextView.setLeftTopString("") + .setLeftString("") + .setLeftBottomString("") + .setCenterTopString("") + .setCenterString("") + .setCenterBottomString("") + .setRightTopString("") + .setRightString("") + .setRightBottomString("") + .setLeftIcon(0) + .setRightIcon(0) + .setRightTvDrawableLeft(null) + .setRightTvDrawableRight(null) + .setCbChecked(true) + .setCbBackground(null); +``` +###### 点击事件(可根据需求选择实现单个或者多个点击事件) +``` + /** + * 根据实际需求对需要的View设置点击事件 + */ + superTextView.setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener() { + @Override + public void onClickListener() { + string = "整个item的点击事件"; + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setLeftTopTvClickListener(new SuperTextView.OnLeftTopTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getLeftTopString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setLeftTvClickListener(new SuperTextView.OnLeftTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getLeftString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setLeftBottomTvClickListener(new SuperTextView.OnLeftBottomTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getLeftBottomString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setCenterTopTvClickListener(new SuperTextView.OnCenterTopTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getCenterTopString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setCenterTvClickListener(new SuperTextView.OnCenterTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getCenterString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setCenterBottomTvClickListener(new SuperTextView.OnCenterBottomTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getCenterBottomString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setRightTopTvClickListener(new SuperTextView.OnRightTopTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getRightTopString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setRightTvClickListener(new SuperTextView.OnRightTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getRightString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setRightBottomTvClickListener(new SuperTextView.OnRightBottomTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getRightBottomString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }); ``` ###### 使用第三方库(Picasso或者Glide)加载网络图片 ``` - Picasso.with(this) - .load(url) - .placeholder(R.drawable.head_default) - .into((ImageView) superTextView.getView(SuperTextView.leftImageViewId)); + Picasso.with(this).load("https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3860616424,1789830124&fm=80&w=179&h=119&img.PNG") + .placeholder(R.drawable.head_default).into(superTextView.getLeftIconIV()); + + + Glide.with(this).load("https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=219781665,3032880226&fm=80&w=179&h=119&img.JPEG") + .placeholder(R.drawable.head_default).fitCenter().into(superTextView2.getRightIconIV()); + + + Glide.with(this).load("https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3860616424,1789830124&fm=80&w=179&h=119&img.PNG") + .placeholder(R.drawable.head_default) + .into(new SimpleTarget() { + @Override + public void onResourceReady(GlideDrawable resource, GlideAnimation glideAnimation) { + superTextView3.setRightTvDrawableRight(resource); + } + }); ``` ##### 3.2.3、属性说明(以下属性全部可以通过xml文件配置和代码进行设置) @@ -203,169 +243,14 @@ sUseRipple | boolean | 是否使用点击出现波纹效果 sLeftBottomView2IsClickable | boolean | 左下第二个view是否可点击 sBackgroundDrawableRes | reference | 背景资源 -### 4、实现原理 -##### 4.1、需求分析 -> 黑格尔曾说过:存在即合理。SuperTextView的出现应该就是某种需求下的产物。 - -在开发项目的过程中你会发现有很多页面的布局都是类似的,就比如说常见的设置页面,基本上都是图标+文字+图标的格式,而且出现的频率都很高,如果不做处理势必会写很多无用的代码降低开发效率,正因为如此我们为什么不把这一类view统一封装起来呐(其实就是程序猿的懒惰,哈哈),有了这个想法就开始调研市场上主流应用的显示样式,经过调研总结出一套显示方案涵盖了市面上90%以上的布局样式,目的是在以后的使用中快速高效的开发。 - -##### 4.2、代码封装 -> 在介绍封装之前先说一句题外话,其实任何功能的封装并不难,还是看你愿不愿意花时间去做,及时是简单的功能真正实现起来的时候还是会或多或少的遇到一些问题,发现问题解决问题的过程其实就是进步的过程。好了,废话不多说,下边看代码。 - -首先SuperTextView 是继承自 RelativeLayout实现,里边所有布局的添加都是通过Java代码实现的,事先定义好需要的参数名及类型 - -下边只列出部分参数 -``` - private int backgroundColor;//背景颜色 - private int leftTVColor;//左边文字颜色 - private int leftTopTVColor;//左上文字颜色 - private int leftBottomTVColor;//左下文字颜色 - private int leftBottomTVColor2;//左下第二个文字颜色 - private int rightTVColor;//右边文字颜色 - private int centerTVColor;//中间文字颜色 - - private boolean isSingLines = true;//是否单行显示 默认单行 - private int maxLines = 1;//最多几行 默认显示一行 - private int maxEms = 10;//最多几个字 默认显示10个汉子 - - private static final int NONE = 0; - private static final int TOP = 1; - private static final int BOTTOM = 2; - private static final int BOTH = 3; - private static final int DEFAULT = BOTTOM; - -``` -然后就是在构造方法里边去实现各个方法 -``` - public SuperTextView(Context context, AttributeSet attrs) { - super(context, attrs); - mContext = context; - getAttr(attrs); - initLayout(); - } -``` -我们知道系统控件可以从XML中拿到定义好的属性值,那么我们其实也是可以的,首先在attr中定义好相关属性名及字段类型然后通过AttributeSet去拿到相关属性值在进行设置 -``` -private void getAttr(AttributeSet attrs) { - //获取我们在attr中定义的SuperTextView相关属性 - TypedArray typedArray = mContext.obtainStyledAttributes(attrs, R.styleable.SuperTextView); - - //下边展示的各个类型参数的获取方法,drawable、string、boolean、int、px - leftIconRes = typedArray.getDrawable(R.styleable.SuperTextView_sLeftIconRes); - leftTextString = typedArray.getString(R.styleable.SuperTextView_sLeftTextString); - showCheckBox = typedArray.getBoolean(R.styleable.SuperTextView_sRightCheckBoxShow, false); - lineType = typedArray.getInt(R.styleable.SuperTextView_sLineShow, DEFAULT); - topLineMargin = typedArray.getDimensionPixelSize(R.styleable.SuperTextView_sTopLineMargin, defaultLinePadding); - - //获取完之后记得recycle()释放掉资源 - typedArray.recycle(); - } -``` -接下来就拿一个view为例进行说明如何动态添加view及设置相关属性 -``` -/** - * 初始化左边文字 - */ - private void initLeftText() { - leftTV = new TextView(mContext); - leftTextParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - leftTextParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE); - leftTextParams.addRule(RelativeLayout.RIGHT_OF, R.id.sLeftIconId); - setMargin(leftTextParams, leftTVMarginLeft, 0, dip2px(mContext, 10), 0); - leftTV.setId(R.id.sLeftTextId); - leftTV.setLayoutParams(leftTextParams); - leftTV.setText(leftTextString); - //设置Params的方法抽离出来便于以后统一调用 - setTextViewParams(leftTV, isSingLines, maxLines, maxEms); - //设置字体颜色的方法抽离出来便于以后统一调用 - setTextColor(leftTV, leftTVColor); - //设置字体大小的方法抽离出来便于以后统一调用 - setTextSize(leftTV, leftTVSize); - //调用addView方法把我们动态创建的view添加到布局中 - addView(leftTV); - } -``` -初始化完view之后就是要暴露一些方法供外部人员使用了(部分代码示例) -在这里我们返回SuperTextView对象是为了实现链式调用 -``` - /** - * 获取checkbox状态 - * - * @return 返回选择框当前选中状态 - */ - public boolean getCbisChecked() { - boolean isChecked = false; - if (rightCheckBox != null) { - isChecked = rightCheckBox.isChecked(); - } - return isChecked; - } - - /** - * 设置左边文字的颜色 - * - * @param textColor 文字颜色值 - * @return 返回对象 - */ - public SuperTextView setLeftTVColor(int textColor) { - leftTVColor = textColor; - if (leftTV == null) { - initLeftText(); - } else { - leftTV.setTextColor(textColor); - } - return this; - } -``` -最后就是一些回调方法的使用,以点击事件为例 -``` -/** - * 点击事件接口 - * 这里没有使用interface是因为有些方法我们不是一定要实现的 - * 用到哪个方法再去重写方法就可以了 - */ - public static class OnSuperTextViewClickListener { - public void onSuperTextViewClick() { - } - - public void onLeftTopClick() { - } - - public void onLeftBottomClick() { - } - public void onLeftBottomClick2() { - } - - } -``` -相关的set方法拿到OnSuperTextViewClickListener对象 -``` - public SuperTextView setOnSuperTextViewClickListener(OnSuperTextViewClickListener listener) { - onSuperTextViewClickListener = listener; - return this; - } -``` +> 黑格尔曾说过:存在即合理。SuperTextView的出现应该就是某种需求下的产物。 -初始化view的时候在各个view的点击事件中添加相应的回调方法就行了 -``` - if (mLeftTopViewIsClickable) { - leftTopTV.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - if (onSuperTextViewClickListener != null) { - onSuperTextViewClickListener.onLeftTopClick(); - } - } - }); - } -``` -> 以上只是源码中的部分方法拿出来供分析使用,看了之后是不是感觉实现其实很简单,赶紧自己着手实现一个吧! -##### 4.3、总结 -想必看到这里的小伙伴已经对这个库的源码实现方式了解了,这里只是把实现的流程给大家介绍了一下,我又对这个库做了一个简化版的处理,有兴趣的小伙伴可以去读读源码哦,发现哪里写的不妥的地方还请指正。 +## 4、更新日志 -## 5、更新日志 +### V2.0.0 +* 重写SuperTextView,功能更加全面 ### V1.1.2 * 上下分割线添加单独设置左右边距的参数 diff --git a/app/build.gradle b/app/build.gradle index 8a93cd5..d6a26d1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,10 +24,11 @@ dependencies { androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - compile 'com.android.support:appcompat-v7:24.2.1' - testCompile 'junit:junit:4.12' compile project(':library') + compile 'com.android.support:appcompat-v7:24.2.1' compile 'com.squareup.picasso:picasso:2.5.2' + compile 'com.github.bumptech.glide:glide:3.8.0' compile 'com.zhy:base-rvadapter:3.0.3' - compile 'com.github.bumptech.glide:glide:3.7.0' + compile 'com.android.support.constraint:constraint-layout:1.0.2' + testCompile 'junit:junit:4.12' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cab142b..dc9966b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,7 +2,8 @@ - + + - - - + + + + \ No newline at end of file diff --git a/app/src/main/java/com/allen/supertextview/ClickActivity.java b/app/src/main/java/com/allen/supertextview/ClickActivity.java new file mode 100644 index 0000000..eb7301d --- /dev/null +++ b/app/src/main/java/com/allen/supertextview/ClickActivity.java @@ -0,0 +1,88 @@ +package com.allen.supertextview; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.widget.Toast; + +import com.allen.library.SuperTextView; + +public class ClickActivity extends AppCompatActivity { + + private SuperTextView superTextView; + + private String string; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_click); + + superTextView = (SuperTextView) findViewById(R.id.super_tv); + + /** + * 根据实际需求对需要的View设置点击事件 + */ + superTextView.setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener() { + @Override + public void onClickListener() { + string = "整个item的点击事件"; + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setLeftTopTvClickListener(new SuperTextView.OnLeftTopTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getLeftTopString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setLeftTvClickListener(new SuperTextView.OnLeftTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getLeftString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setLeftBottomTvClickListener(new SuperTextView.OnLeftBottomTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getLeftBottomString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setCenterTopTvClickListener(new SuperTextView.OnCenterTopTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getCenterTopString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setCenterTvClickListener(new SuperTextView.OnCenterTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getCenterString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setCenterBottomTvClickListener(new SuperTextView.OnCenterBottomTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getCenterBottomString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setRightTopTvClickListener(new SuperTextView.OnRightTopTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getRightTopString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setRightTvClickListener(new SuperTextView.OnRightTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getRightString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }).setRightBottomTvClickListener(new SuperTextView.OnRightBottomTvClickListener() { + @Override + public void onClickListener() { + string = superTextView.getRightBottomString(); + Toast.makeText(ClickActivity.this, string, Toast.LENGTH_SHORT).show(); + } + }); + + } +} diff --git a/app/src/main/java/com/allen/supertextview/ListActivity.java b/app/src/main/java/com/allen/supertextview/ListActivity.java index ab50434..efa8b70 100644 --- a/app/src/main/java/com/allen/supertextview/ListActivity.java +++ b/app/src/main/java/com/allen/supertextview/ListActivity.java @@ -51,8 +51,8 @@ private List getData() { for (int i = 0; i < 10; i++) { NewsBean newsBean = new NewsBean(); newsBean.setImgUrl(url[i]); - newsBean.setTitle("新闻标题----"+i); - newsBean.setTime("2016.10.31----"+i); + newsBean.setTitle("新闻标题"+i); + newsBean.setTime("哈佛有嘻哈教你如何用一个freestyle轻松毕业"+i); newsBeanList.add(newsBean); } return newsBeanList; diff --git a/app/src/main/java/com/allen/supertextview/MainActivity.java b/app/src/main/java/com/allen/supertextview/MainActivity.java index 9889fd8..a4e5301 100644 --- a/app/src/main/java/com/allen/supertextview/MainActivity.java +++ b/app/src/main/java/com/allen/supertextview/MainActivity.java @@ -1,21 +1,16 @@ package com.allen.supertextview; import android.content.Intent; -import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; -import com.allen.library.SuperTextView; - public class MainActivity extends AppCompatActivity implements View.OnClickListener { - private SuperTextView superTextView; - private Drawable drawable; + private Button button0, button1, button2, button3, button4, button5, button6, button7,button8; - private Button button0,button1,button2,button3,button4,button5,button6,button7; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -29,6 +24,7 @@ protected void onCreate(Bundle savedInstanceState) { button5 = (Button) findViewById(R.id.button5); button6 = (Button) findViewById(R.id.button6); button7 = (Button) findViewById(R.id.button7); + button8 = (Button) findViewById(R.id.button8); button0.setOnClickListener(this); button1.setOnClickListener(this); @@ -38,102 +34,57 @@ protected void onCreate(Bundle savedInstanceState) { button5.setOnClickListener(this); button6.setOnClickListener(this); button7.setOnClickListener(this); + button8.setOnClickListener(this); } @Override public void onClick(View v) { Intent intent = new Intent(); - switch (v.getId()){ + switch (v.getId()) { case R.id.button0: - intent.setClass(this,TypeActivity.class); - intent.putExtra("type",0); + intent.setClass(this, TypeActivity.class); + intent.putExtra("type", 0); startActivity(intent); break; case R.id.button1: - intent.setClass(this,TypeActivity.class); - intent.putExtra("type",1); + intent.setClass(this, TypeActivity.class); + intent.putExtra("type", 1); startActivity(intent); break; case R.id.button2: - intent.setClass(this,TypeActivity.class); - intent.putExtra("type",2); + intent.setClass(this, TypeActivity.class); + intent.putExtra("type", 2); startActivity(intent); break; case R.id.button3: - intent.setClass(this,TypeActivity.class); - intent.putExtra("type",3); + intent.setClass(this, TypeActivity.class); + intent.putExtra("type", 3); startActivity(intent); break; case R.id.button4: - intent.setClass(this,TypeActivity.class); - intent.putExtra("type",4); + intent.setClass(this, TypeActivity.class); + intent.putExtra("type", 4); startActivity(intent); break; case R.id.button5: - intent.setClass(this,TypeActivity.class); - intent.putExtra("type",5); + intent.setClass(this, TypeActivity.class); + intent.putExtra("type", 5); startActivity(intent); break; case R.id.button6: -// intent.setClass(this, ListActivity.class); - intent.setClass(this,TypeActivity.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); + intent.setClass(this, ListActivity.class); + startActivity(intent); + break; + case R.id.button8: + intent.setClass(this, ClickActivity.class); startActivity(intent); break; } } - /** - * 可以通过链式设置大部分常用的属性值 - */ -// private void setSuperTextView() { -// superTextView.setLeftIcon(drawable) -// .setLeftString("") -// .setLeftTVColor(0) -// .setLeftTopString("") -// .setLeftTopTVColor(0) -// .setLeftBottomString("") -// .setLeftBottomTVColor(0) -// .setLeftBottomString2("") -// .setLeftBottomTVColor2(0) -// .setRightString("") -// .setRightTVColor(0) -// .setCbChecked(true) -// .setCbBackground(drawable) -// .setRightIcon(drawable) -// .setRightString("") -// .setRightTVColor(0) -// .setLeftString("") -// .setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener() { -// @Override -// public void onSuperTextViewClick() { -// super.onSuperTextViewClick(); -// //do something -// } -// -// @Override -// public void onLeftTopClick() { -// super.onLeftTopClick(); -// //do something -// } -// -// @Override -// public void onLeftBottomClick() { -// super.onLeftBottomClick(); -// //do something -// } -// -// @Override -// public void onLeftBottomClick2() { -// super.onLeftBottomClick2(); -// //do something -// } -// }); -// } } diff --git a/app/src/main/java/com/allen/supertextview/TypeActivity.java b/app/src/main/java/com/allen/supertextview/TypeActivity.java index a7d68bf..0bd2aff 100644 --- a/app/src/main/java/com/allen/supertextview/TypeActivity.java +++ b/app/src/main/java/com/allen/supertextview/TypeActivity.java @@ -2,9 +2,12 @@ import android.os.Bundle; import android.support.v7.app.AppCompatActivity; -import android.widget.ImageView; import com.allen.library.SuperTextView; +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.resource.drawable.GlideDrawable; +import com.bumptech.glide.request.animation.GlideAnimation; +import com.bumptech.glide.request.target.SimpleTarget; import com.squareup.picasso.Picasso; /** @@ -13,10 +16,10 @@ public class TypeActivity extends AppCompatActivity { private int type; - private SuperTextView superTextView,superTextView2,superTextView3; + private SuperTextView superTextView, superTextView2, superTextView3; @Override - protected void onCreate( Bundle savedInstanceState) { + protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); type = getIntent().getIntExtra("type", 0); switch (type) { @@ -42,25 +45,31 @@ protected void onCreate( Bundle savedInstanceState) { case 6: setContentView(R.layout.layout6); break; + case 7: + setContentView(R.layout.layout7); + break; } - - } private void setData() { superTextView = (SuperTextView) findViewById(R.id.super_tv1); superTextView2 = (SuperTextView) findViewById(R.id.super_tv2); - - superTextView.setLeftTopString("姓名").setLeftBottomString("188********"); - superTextView2.setLeftTopString("姓名").setLeftBottomString("181********"); - + superTextView3 = (SuperTextView) findViewById(R.id.super_tv3); Picasso.with(this).load("https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3860616424,1789830124&fm=80&w=179&h=119&img.PNG") - .placeholder(R.drawable.head_default).into((ImageView) superTextView.getView(SuperTextView.leftImageViewId)); - Picasso.with(this).load("https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=219781665,3032880226&fm=80&w=179&h=119&img.JPEG") - .placeholder(R.drawable.head_default).into((ImageView) superTextView2.getView(SuperTextView.rightImageViewId)); + .placeholder(R.drawable.head_default).into(superTextView.getLeftIconIV()); + Glide.with(this).load("https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=219781665,3032880226&fm=80&w=179&h=119&img.JPEG") + .placeholder(R.drawable.head_default).fitCenter().into(superTextView2.getRightIconIV()); + Glide.with(this).load("https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=3860616424,1789830124&fm=80&w=179&h=119&img.PNG") + .placeholder(R.drawable.head_default) + .into(new SimpleTarget() { + @Override + public void onResourceReady(GlideDrawable resource, GlideAnimation glideAnimation) { + superTextView3.setRightTvDrawableRight(resource); + } + }); } diff --git a/app/src/main/java/com/allen/supertextview/adapter/NewsAdapter.java b/app/src/main/java/com/allen/supertextview/adapter/NewsAdapter.java index b9fd99c..4ad5521 100644 --- a/app/src/main/java/com/allen/supertextview/adapter/NewsAdapter.java +++ b/app/src/main/java/com/allen/supertextview/adapter/NewsAdapter.java @@ -2,9 +2,10 @@ import android.content.Context; +import com.allen.library.SuperTextView; import com.allen.supertextview.R; import com.allen.supertextview.bean.NewsBean; -import com.allen.library.SuperTextView; +import com.squareup.picasso.Picasso; import com.zhy.adapter.recyclerview.CommonAdapter; import com.zhy.adapter.recyclerview.base.ViewHolder; @@ -16,7 +17,7 @@ public class NewsAdapter extends CommonAdapter { private Context mContext; - private SuperTextView superTextView; + public NewsAdapter(Context context, List datas) { super(context, R.layout.item, datas); mContext = context; @@ -24,11 +25,10 @@ public NewsAdapter(Context context, List datas) { @Override protected void convert(ViewHolder holder, NewsBean newsBean, int position) { -// if (superTextView ==null){ -// superTextView = holder.getView(R.id.super_tv); -// } -// holder.setText(superTextView.getViewId(SuperTextView.leftTopTextViewId),newsBean.getTitle()); -// holder.setText(superTextView.getViewId(SuperTextView.leftBottomTextViewId),newsBean.getTime()); -// Picasso.with(mContext).load(newsBean.getImgUrl()).into((ImageView) SuperTextView.getView(SuperTextView.leftImageViewId)); + + ((SuperTextView) holder.getView(R.id.super_tv)).setLeftTopString(newsBean.getTitle()).setLeftBottomString(newsBean.getTime()); + Picasso.with(mContext).load(newsBean.getImgUrl()).placeholder(R.drawable.head_default + ).into(((SuperTextView) holder.getView(R.id.super_tv)) + .getLeftIconIV()); } } diff --git a/app/src/main/res/layout/activity_click.xml b/app/src/main/res/layout/activity_click.xml new file mode 100644 index 0000000..cd10967 --- /dev/null +++ b/app/src/main/res/layout/activity_click.xml @@ -0,0 +1,25 @@ + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 37dae11..51a883b 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -35,48 +35,57 @@ android:id="@+id/button0" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="组合0" /> + android:text="所有组合" />