ImageSpan的使用
来源:互联网 发布:python网络爬虫是什么 编辑:程序博客网 时间:2024/06/05 16:03
编辑框中加图片,以前一直以为很复杂,后来发现android有些类已经很好的实现了这些功能.
代码如下:
- mSubjectDetailView = (TextView) findViewById(R.id.subject_detail);
- CharSequence text = "如图所示★,dsfdsfdddd,如果fdsfs★东东";
- SpannableStringBuilder builder = new SpannableStringBuilder(text);
- String rexgString = "★";
- Pattern pattern = Pattern.compile(rexgString);
- Matcher matcher = pattern.matcher(text);
- while (matcher.find()) {
- builder.setSpan(
- new ImageSpan(this, R.drawable.ic_launcher), matcher.start(), matcher
- .end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- }
- mSubjectDetailView.setText(builder);
- mSubjectDetailView = (TextView) findViewById(R.id.subject_detail);
- CharSequence text = "如图所示★,dsfdsfdddd,如果fdsfs★东东";
- SpannableStringBuilder builder = new SpannableStringBuilder(text);
- String rexgString = "★";
- Pattern pattern = Pattern.compile(rexgString);
- Matcher matcher = pattern.matcher(text);
- while (matcher.find()) {
- builder.setSpan(
- new ImageSpan(this, R.drawable.ic_launcher), matcher.start(), matcher
- .end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- }
- mSubjectDetailView.setText(builder);
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity" >
- <TextView
- android:id="@+id/my_title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:layout_centerVertical="true"
- android:text="@string/hello_world" />
- <TextView
- android:id="@+id/subject_detail"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:minHeight="50dp"
- android:gravity="center_vertical"
- android:text="subject"
- android:textColor="@android:color/primary_text_light_nodisable"
- android:background="@android:color/white"
- android:textSize="25sp" />
- </RelativeLayout>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity" >
- <TextView
- android:id="@+id/my_title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:layout_centerVertical="true"
- android:text="@string/hello_world" />
- <TextView
- android:id="@+id/subject_detail"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:minHeight="50dp"
- android:gravity="center_vertical"
- android:text="subject"
- android:textColor="@android:color/primary_text_light_nodisable"
- android:background="@android:color/white"
- android:textSize="25sp" />
- </RelativeLayout>
效果:
0 0
- ImageSpan的使用
- 【UBB】 ImageSpan的使用
- ImageSpan的使用
- ImageSpan的使用
- ImageSpan的使用
- ImageSpan的使用
- Android中ImageSpan的使用
- 使用ImageSpan图标不截断的方法
- Android-ImageSpan的使用实现图文并排
- EditText、ImageSpan和SpannableString的配合使用
- android 图文一起 textview SpannableString和ImageSpan类的使用
- SpannableString、ImageSpan的用途
- 可点击的ImageSpan
- VerticalImageSpan,垂直居中的ImageSpan
- 获取网络图片的ImageSpan
- 关于Android使用TextView+ImageSpan同一行文字图片居中的问题
- Android textView文字添加图片 imageSpan使用
- TextView中使用ImageSpan显示“...”问题
- ngnix的安装小记
- mm编译 问题
- VS生成DLL没有生成LIB文件的解决方法
- JVM系列之JVM体系(一)
- bzoj 4134 ljw和lzr的hack比赛
- ImageSpan的使用
- swift-基本操作02-自增和复合赋值运算符
- 新技能get√丨抢了那么多红包,你知道算法是怎么实现的吗
- label 根据内容text确定控件的大小 分为单行/多行文字
- Music
- MySQL中select * for update锁表的问题(悲观锁)
- matlab 扩大虚拟内存
- git查看某次提交/更新所更改的文件
- Spring 使用注解方式进行事务管理