textview点击展开全部或收起,内容过长显示省略号,设置行间距,字间距,跑马灯显示

 跑马灯显示

 

android:ellipsize="marquee"
android:singleLine="true"
paomad.setSelected(true);

 

使用RelativeLayout可以使用图标点击旋转,展开textview或收缩textview

<RelativeLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_marginLeft="15dp"android:layout_marginRight="6dp"android:layout_marginTop="7dp"android:layout_marginBottom="7dp"android:gravity="center_vertical"><TextViewandroid:id="@+id/onete"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentStart="true"android:layout_centerVertical="true"android:text="@string/wgms"android:textColor="@color/numtext"android:textSize="15dp" /><TextViewandroid:id="@+id/wgmiaostext"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="80dp"android:ellipsize="end"android:lineSpacingExtra="4dp"android:lines="2"android:text="申报过期申报报过期申报过期申过期申报过期申报过期申报报报报报过期申报过期"android:textColor="@color/hometextc"android:textSize="15dp" /><ImageViewandroid:id="@+id/more_image"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentEnd="true"android:layout_alignParentBottom="true"android:src="@mipmap/xj_03"/></RelativeLayout>

Java代码如下

private boolean ifupdown=true;
@OnClick({R.id.backligxwbdata,R.id.more_image})
public void onClick(View view) {switch (view.getId()) {case R.id.backligxwbdata:onBackPressed();break;case R.id.more_image:if (ifupdown){Animation anim =new RotateAnimation(0f, 180f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);anim.setFillAfter(true); // 设置保持动画最后的状态anim.setDuration(500); // 设置动画时间anim.setInterpolator(new AccelerateInterpolator()); // 设置插入器more_image.startAnimation(anim);//图标旋转向上或向下ifupdown = !ifupdown;double d = (double) weiguidesc.length() / 18;//文本长度除以每行字符长度int  okcprogress = (int) (Math.floor(d))+1;//除数取整,也就是行数Log.i("lgq","lllll===-"+weiguidesc.length()+"......."+okcprogress);wgmiaostext.setLines(okcprogress);//展开全部}else {Animation anim =new RotateAnimation(180f, 0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);anim.setFillAfter(true); // 设置保持动画最后的状态anim.setDuration(500); // 设置动画时间anim.setInterpolator(new AccelerateInterpolator()); // 设置插入器more_image.startAnimation(anim);wgmiaostext.setLines(2);//收缩为原始两行               ifupdown = !ifupdown;}break;}
}

实现展开收起方法2:

(1)资源

<color name="color_8290AF">#8290AF</color>
<color name="color_232323">#232323</color>

attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources><declare-styleable name="ExpandTextView"><attr name="showLines" format="integer"/></declare-styleable></resources>

layout_expand_text.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><TextViewandroid:id="@+id/contentText"android:layout_width="match_parent"android:layout_height="wrap_content"android:textColor="@color/color_232323"android:textSize="14sp"android:text=""/><TextViewandroid:id="@+id/textState"android:layout_width="match_parent"android:layout_height="wrap_content"android:textSize="14sp"android:textColor="@color/color_8290AF"android:paddingTop="5dp"android:paddingBottom="5dp"android:text=""/></LinearLayout>

(2)自定义textview

public class ExpandTextView extends LinearLayout {public static final int DEFAULT_MAX_LINES = 3;//最大的行数private TextView contentText;private TextView textState;private int showLines;private ExpandStatusListener expandStatusListener;private boolean isExpand;public ExpandTextView(Context context) {super(context);initView();}public ExpandTextView(Context context, AttributeSet attrs) {super(context, attrs);initAttrs(attrs);initView();}public ExpandTextView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);initAttrs(attrs);initView();}private void initView() {setOrientation(LinearLayout.VERTICAL);LayoutInflater.from(getContext()).inflate(R.layout.layout_expand_text, this);contentText = (TextView) findViewById(R.id.contentText);contentText.setLineSpacing(8,1);//行间距contentText.setLetterSpacing(0.5f);          //字间距if(showLines > 0){contentText.setMaxLines(showLines);}textState = (TextView) findViewById(R.id.textState);textState.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View view) {String textStr = textState.getText().toString().trim();if("全文".equals(textStr)){contentText.setMaxLines(Integer.MAX_VALUE);textState.setText("收起");setExpand(true);}else{contentText.setMaxLines(showLines);textState.setText("全文");setExpand(false);}//通知外部状态已变更if(expandStatusListener != null){expandStatusListener.statusChange(isExpand());}}});}private void initAttrs(AttributeSet attrs) {TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.ExpandTextView, 0, 0);try {showLines = typedArray.getInt(R.styleable.ExpandTextView_showLines, DEFAULT_MAX_LINES);}finally {typedArray.recycle();}}public void setText(final CharSequence content){contentText.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {@Overridepublic boolean onPreDraw() {// 避免重复监听contentText.getViewTreeObserver().removeOnPreDrawListener(this);int linCount = contentText.getLineCount();if(linCount > showLines){if(isExpand){contentText.setMaxLines(Integer.MAX_VALUE);textState.setText("收起");}else{contentText.setMaxLines(showLines);textState.setText("全文");}textState.setVisibility(View.VISIBLE);}else{textState.setVisibility(View.GONE);}return true;}});contentText.setText(content);}public void setExpand(boolean isExpand){this.isExpand = isExpand;}public boolean isExpand(){return this.isExpand;}public void setExpandStatusListener(ExpandStatusListener listener){this.expandStatusListener = listener;}public static interface ExpandStatusListener{void statusChange(boolean isExpand);}
}

调用:

<com.example.my35.ExpandTextViewandroid:id="@+id/expand_textView"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:ellipsize="end"android:lineSpacingExtra="3dp"android:maxLines="5"android:textSize="16sp"app:layout_constraintRight_toRightOf="parent"/>
ExpandTextView textView1 =findViewById(R.id.expand_textView);
textView1.setText("分为非我仿佛威风威风为任务范围范围分为非危房危房危房威锋网分为非仍无法" +"为非危房危房危房威锋网分为非仍无法危房违法未范围范围分为非危房危房任务分为分为分为我分为非我仿佛威风威" +"风为任务范围范围分为非危房危房危房威锋网分为非仍无法危房违法未范围范围分为非危房危房任务分为分为分为我");

单行省略

android:singleLine="true"
android:ellipsize="end"


多行省略

android:maxLines="3"
android:ellipsize="end"


行距

android:lineSpacingExtra="6dp"

contentText.setLineSpacing(8,1);//行间距
contentText.setLetterSpacing(0.5f);          //字间距

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/415640.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

在windows 2003系统安装oracle11G出现的问题

最近因为项目的需要&#xff0c;需要在虚拟机中搭建oracle11g&#xff0c;结果在安装中出现了一些平时没遇到过的问题&#xff0c;暂且记录下来。 问题报告&#xff1a; 正在检查网络配置要求... 检查完成。此次检查的总体结果为: 失败 <<<< 问题: 安装检测到系统…

前端学习(2615):数据映射map

第一步 引入 第二步 计算属性

Java的运算符-取整,取绝对值,取余数,四舍五入

double d (double) weiguidesc.length() / 18;//文本长度除以每行字符长度int okcprogress (int) (Math.floor(d))1;//除数取整&#xff0c;也就是行数 float ab 15f/4f; int ac (int)ab; Log.i("lgq","......ac"ac"........ab"ab); 结果…

hapi和typescript构建项目(正在更新中)

1、初始化项目 初始化 yarn init生成配置文件tsconfig.json tsc --init 注意&#xff1a;将outDir设置为"outDir": "dist" 全部编译配置文档地址&#xff1a;https://www.w3cschool.cn/typescript/typescript-compiler-options.html 安装工具concurren…

ES6展开运算符(...)

这是在网上看见的es6展开运算符的总结&#xff0c;原文地址&#xff1a;http://www.jianshu.com/p/c5230c11781b 作者&#xff1a;可木Changer链接&#xff1a;http://www.jianshu.com/p/c5230c11781b來源&#xff1a;简书 总结还可以&#xff0c;借鉴下 三个点(...)在es6中&am…

QC与IE8 、WINDOWS 7 兼容问题的解决方案

QC与win7不兼容 1、 通过开始菜单搜索框&#xff0c;输入UAC&#xff0c;会出现“更改用户帐户控制设置”&#xff08;ChangeUser Account Control菜单 项。点击打开后&#xff0c;通过滚动条选择“从不通知”。 2、 打开cmd命令行&#xff0c;运行如下命令&#xff1a;bcd…

修改build:gradle版本

打开项目build.gradle文件dependencies下找到classpath com.android.tools.build:gradle:3.1.2 // classpath org.greenrobot:greendao-gradle-plugin:3.0.0 修改数字部分&#xff0c;如2.3.0或3.0.1或3.0.0等等 try即可

process.cwd __dirname __filename 区别

process.cwd() 就是说process.cwd()返回的是当前Node.js进程执行时的工作目录。 __dirname: 当前模块的目录名。 等同于 __filename 的 path.dirname()。__dirname 实际上不是一个全局变量&#xff0c;而是每个模块内部的。 __filename 获得当前执行文件的带有完整绝对路径的…

Oracle 数据泵使用——导入、导出

今天重新整理了下数据泵的使用&#xff0c;用数据泵完成数据的导出、导入&#xff0c;真的很方便&#xff0c;现将操作及语句记录下来。 第一步&#xff1a;导出数据 用数据泵导出原库的数据&#xff0c;这个不需要进行其他的操作&#xff0c;直接在导出的机器直接执行下面语…

Error:Connection timed out: connect

1、打开项目build.gradle&#xff0c;找到dependencies {classpath com.android.tools.build:gradle:3.0.1// NOTE: Do not place your application dependencies here; they belong// in the individual module build.gradle files } 修改版本号为当前安装的版本号&#xff0c…

Microsoft SQL Server 全角转半角函数

先创建函数&#xff0c;函数如下 CREATE FUNCTION f_Convert( str NVARCHAR(4000), --要转换的字符串 flag bit --转换标志,0转换成半角,1转换成全角 )RETURNS nvarchar(4000) AS BEGIN DECLARE pat nvarchar(8),step int,i int,spc int IF flag0 SELECT patN%[&#xff01;-&a…

typescript mongodb 教程搜集

https://tutorialedge.net/typescript/typescript-mongodb-beginners-tutorial/

工作118:封装一个带有对话框的button组件

buttondialog.vue <!--定义一个有按钮的对话框 相当于dialog和按钮组合使用--> <template><!-- 有按钮的对话框 这个位置的代码会被包裹过去--><!--close-on-click-modal 是否可以通过点击 modal 关闭 Dialog append-to-body控制不能出现遮挡层--><…

测试常用工具下载地址,LR11、QC11

LR11下载地址&#xff1a; http://kuai.xunlei.com/d/QRNIUASALOIE QC11&#xff08;ALM 11&#xff09;下载地址&#xff1a; http://www.everbox.com/f/lZZqM1dpRAWNhjVrv8EZJE8Z4W

Android 获取经纬度,地理位置,省市区

申请百度key&#xff1a;http://lbsyun.baidu.com/ 1、jar包下载地址&#xff1a;https://pan.baidu.com/s/1J-boj0ct9oJ8YjXMR8X4KA 下载并复制到libs下&#xff0c;Add As Library 如需获取SHA1值&#xff1a;https://blog.csdn.net/meixi_android/article/details/72547966…

PHP中的__get()和__set()方法获取设置私有属性

在类的封装中&#xff0c;获取属性可以自定义getXXX()和setXXX()方法&#xff0c;当一个类中有多个属性时&#xff0c;使用这种方式就会很麻烦。为此PHP5中预定义了__get()和__set()方法&#xff0c;其中__get()方法用于获取私有成员属性值&#xff0c;__set()方法用于为私有成…

node 遍历读取制定后缀文件名

我的需求就是读取指定文件夹中&#xff0c;后缀为.js的文件。有两种方法解决。 1、不依赖插件&#xff1a; import * as fs from fs; import * as Path from path; const files fs.readdirSync(__dirname).filter(function (file) {return Path.extname(file).toLowerCase() …

前端学习(2618):vue插槽--默认插槽

插槽就是子组件中的提供给父组件使用的一个占位符&#xff0c;用<slot></slot> 表示&#xff0c;父组件可以在这个占位符中填充任何模板代码&#xff0c;如 HTML、组件等&#xff0c;填充的内容会替换子组件的<slot></slot>标签。 如下代码&#xff1…