当前位置: 首页 > news >正文

佛山附近做网站的公司广州网站建设系统

佛山附近做网站的公司,广州网站建设系统,定制企业app开发,中国网站设计师实现效果如下: 如上,将头像后面的东西看作一个整体,因为不能影响后面内容的换行,且前面控件的长度是可变的,所以采用自定义View的方法来实现: /*** CSDN深海呐 https://blog.csdn.net/qq_40945489/articl…

实现效果如下:


如上,将头像后面的东西看作一个整体,因为不能影响后面内容的换行,且前面控件的长度是可变的,所以采用自定义View的方法来实现:

/***  CSDN深海呐 https://blog.csdn.net/qq_40945489/article/details/109399596*/
public class TagTextView extends AppCompatTextView {private Context mContext;private TextView mTabText;private StringBuffer mContentStringBuffer;//必须重写所有的构造器,否则可能会出现无法inflate布局的错误!public TagTextView(Context context) {super(context);mContext = context;}public TagTextView(Context context, AttributeSet attrs) {super(context, attrs);mContext = context;}public TagTextView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);mContext = context;}public void setContentAndTag(String content, List<String> dataList, List<Integer> typeList) {mContentStringBuffer = new StringBuffer();for (String item : dataList) {//将内容添加到content,用drawable替代这些内容所占的位置mContentStringBuffer.append(item);}mContentStringBuffer.append(content);SpannableString spannableString = new SpannableString(mContentStringBuffer);for (int i = 0; i < dataList.size(); i++) {String item = dataList.get(i);View view = LayoutInflater.from(mContext).inflate(R.layout.layout_texttab, null);//R.layout.tag是每个标签的布局switch (typeList.get(i)){case 1:view = LayoutInflater.from(mContext).inflate(R.layout.layout_texttab1, null);break;case 2:view = LayoutInflater.from(mContext).inflate(R.layout.layout_texttab2, null);break;}mTabText = view.findViewById(R.id.tabText);mTabText.setText(item);Bitmap bitmap = convertViewToBitmap(view);Drawable d = new BitmapDrawable(bitmap);d.setBounds(0, 0, mTabText.getWidth(), mTabText.getHeight());ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM);//图片对齐底部int startIndex;int endIndex;startIndex = getLastLength(dataList, i );endIndex = startIndex + item.length();spannableString.setSpan(span, startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);}setText(spannableString);setGravity(Gravity.CENTER_VERTICAL);}private static Bitmap convertViewToBitmap(View view) {view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());view.buildDrawingCache();Bitmap bitmap = view.getDrawingCache();return bitmap;}private int getLastLength(List<String> list, int maxLength) {int length = 0;for (int i = 0; i < maxLength; i++) {length += list.get(i).length();}return length;}
}

使用举例:  (😂抱歉啊使用这边没有用Java写,不会Kotlin的应该也能看懂啥意思)

class MainActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)initView();}private fun initView() {setText("很长很长的一段话一段话一段话  真的很长很长很长......")}private fun setText(string: String) {val title : TagTextView = findViewById(R.id.main_text)val dataList = arrayListOf<String>()dataList.add("用户的名字")dataList.add("48")dataList.add("  长老")val dataListType = arrayListOf<Int>()dataListType.add(0);dataListType.add(1);dataListType.add(2);title.setContentAndTag(""+string+"", dataList,dataListType)}
}

activity_main.xml:

<LinearLayout 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"android:orientation="vertical"tools:context=".MainActivity"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:src="@mipmap/head" /><com.example.demo.TagTextViewandroid:id="@+id/main_text"android:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center"android:text="当前是用户发的一段话很长很长的一段话,非常长非常长!!!!!!"android:textColor="@color/TextColor"android:textSize="12sp" /></LinearLayout></LinearLayout>

la:

<LinearLayout 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"android:orientation="vertical"tools:context=".MainActivity"><TextViewandroid:id="@+id/tabText"android:layout_width="wrap_content"android:layout_height="wrap_content"android:drawablePadding="6dp"android:drawableRight="@mipmap/sex"android:gravity="center"android:paddingRight="8dp"android:text="CSDN深海呐"android:textColor="@color/HeadText"android:textSize="12sp" /></LinearLayout>

dataListType的 0,1,2 分别对应三种不同的布局赋值,XML文件我就不全部发出来了,这里可以自主发挥。

http://www.hkea.cn/news/935188/

相关文章:

  • 网站建设的图片叠加步骤过程2021年搜索引擎排名
  • 网站链接到邮箱怎么做搜索引擎推广试题
  • 十堰城市建设网站制作自己的网站
  • 传媒网站建设公司深圳百度seo优化
  • 公司需要网站 该怎么做公司推广咨询
  • 高中男女做那个视频网站seo做的好的网站
  • 网站建设 摄影服务上海seo网站排名优化公司
  • 网页设计中html代码seo博客网站
  • 怎样建设小游戏网站google关键词搜索技巧
  • 淘宝 客要推广网站怎么做全媒体广告代理
  • 那个b2b网站可以做外贸武汉全网推广
  • 深圳css3网站开发多少钱如何策划一个营销方案
  • 织梦统计网站访问量代码网络营销公司如何建立
  • 外贸营销型网站建设今日最新重大新闻
  • 个性化定制网站长春网络推广优化
  • 合肥庐阳区疫情最新消息seo优化首页
  • h5网站制作接单最新中高风险地区名单
  • 北京市住房城乡建设委网站公司怎么在网上推广
  • 网站建设首页怎样插入视频百度指数在线查询小程序
  • 青州网站制作哪家好aso优化哪家好
  • wordpress做网站优点郑州网站seo优化
  • 宝安做棋牌网站建设找哪家公司好湖南长沙疫情最新消息
  • 四川专业网站建设中国十大企业培训机构排名
  • 怎么切页面做网站灰色词首页排名接单
  • 网站右侧浮动广告代码百度推广代理公司广州
  • 固原建站公司旺道seo推广系统怎么收费
  • 适合做外链的网站海外广告联盟平台推广
  • 建筑模板规格型号郑州厉害的seo顾问
  • ppt做书模板下载网站有哪些内容国际婚恋网站排名
  • 上海网站建设内容更新网络营销策划目的