欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android TextView實(shí)現(xiàn)圖文混合編排的方法

 更新時(shí)間:2017年07月12日 11:02:33   作者:zhangphil  
這篇文章主要為大家詳細(xì)介紹了Android TextView實(shí)現(xiàn)圖文混合編排的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android TextView圖文混合編排的具體代碼,供大家參考,具體內(nèi)容如下

實(shí)現(xiàn)技術(shù)細(xì)節(jié)不難,兩個(gè)要點(diǎn):

1、html代碼的混合編寫。
2、重寫ImageGetter。

例如:

布局:

<?xml version="1.0" encoding="utf-8"?>
<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="zhangphil.app.MainActivity">

 <TextView
 android:id="@+id/text1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" />

 <TextView
 android:id="@+id/text2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" />

 <TextView
 android:id="@+id/text3"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:ellipsize="end"
 android:maxLines="1" />

 <TextView
 android:id="@+id/text4"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:ellipsize="end"
 android:maxLines="1" />
</LinearLayout>

 Java代碼:

package zhangphil.app;

import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);

 TextView text1 = (TextView) findViewById(R.id.text1);
 TextView text2 = (TextView) findViewById(R.id.text2);
 TextView text3 = (TextView) findViewById(R.id.text3);
 TextView text4 = (TextView) findViewById(R.id.text4);

 String s = "zhang phil @ csdn Android TextView圖文混編";

 CharSequence cs1 = Html.fromHtml(stringMixWithImage1(s), imgageGetter, null);
 text1.setText(cs1);

 CharSequence cs2 = Html.fromHtml(stringMixWithImage2(s), imgageGetter, null);
 text2.setText(cs2);

 CharSequence cs3 = Html.fromHtml(stringMixWithImage3(s), imgageGetter, null);
 text3.setText(cs3);

 CharSequence cs4 = Html.fromHtml(stringMixWithImage4(s), imgageGetter, null);
 text4.setText(cs4);
 }

 private String stringMixWithImage1(String string) {
 return string + "1 " + "<img src='" + R.mipmap.ic_launcher + "'/>" + " " + "<img src='" + R.mipmap.ic_launcher + "'/>" + " " + "<img src='" + R.mipmap.ic_launcher + "'/>" + " ";
 }

 private String stringMixWithImage2(String string) {
 return "2 " + "<img src='" + R.mipmap.ic_launcher + "'/>" + " " + "<img src='" + R.mipmap.ic_launcher + "'/>" + " " + "<img src='" + R.mipmap.ic_launcher + "'/>" + " " + string;
 }

 private String stringMixWithImage3(String string) {
 return string + "3 " + "<img src='" + R.mipmap.ic_launcher + "'/>" + " " + "<img src='" + R.mipmap.ic_launcher + "'/>" + " " + "<img src='" + R.mipmap.ic_launcher + "'/>" + " ";
 }

 private String stringMixWithImage4(String string) {
 return "4 " + "<img src='" + R.mipmap.ic_launcher + "'/>" + " " + "<img src='" + R.mipmap.ic_launcher + "'/>" + " " + "<img src='" + R.mipmap.ic_launcher + "'/>" + " " + string;
 }

 private Html.ImageGetter imgageGetter = new Html.ImageGetter() {
 @Override
 public Drawable getDrawable(String source) {
  int id = Integer.parseInt(source);
  Drawable d = ContextCompat.getDrawable(getApplicationContext(), id);
  d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
  return d;
 }
 };
}

代碼運(yùn)行結(jié)果:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android 實(shí)現(xiàn)簽到足跡功能

    Android 實(shí)現(xiàn)簽到足跡功能

    這篇文章主要介紹了Android 實(shí)現(xiàn)簽到足跡功能的示例,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下
    2021-04-04
  • Android ViewFlipper用法實(shí)例分析

    Android ViewFlipper用法實(shí)例分析

    這篇文章主要介紹了Android ViewFlipper用法,結(jié)合實(shí)例形式分析了ViewFlipper圖片操作的相關(guān)技巧,需要的朋友可以參考下
    2016-01-01
  • Android Studio下添加assets目錄的實(shí)現(xiàn)方法

    Android Studio下添加assets目錄的實(shí)現(xiàn)方法

    下面小編就為大家?guī)?lái)一篇Android Studio下添加assets目錄的實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-03-03
  • Android實(shí)現(xiàn)保持屏幕常亮功能

    Android實(shí)現(xiàn)保持屏幕常亮功能

    本篇文章主要介紹了Android實(shí)現(xiàn)保持屏幕常亮功能,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-11-11
  • Android實(shí)現(xiàn)折線走勢(shì)圖

    Android實(shí)現(xiàn)折線走勢(shì)圖

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)折線走勢(shì)圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-11-11
  • Android PopUpWindow使用詳解

    Android PopUpWindow使用詳解

    PopupWindow與AlertDialog最關(guān)鍵的區(qū)別是AlertDialog不能指定顯示位置,只能默認(rèn)顯示在屏幕最中間(當(dāng)然也可以通過(guò)設(shè)置WindowManager參數(shù)來(lái)改變位置)。而PopupWindow是可以指定顯示位置的,隨便哪個(gè)位置都可以,更加靈活
    2021-10-10
  • android編程實(shí)現(xiàn)局部界面動(dòng)態(tài)切換的方法

    android編程實(shí)現(xiàn)局部界面動(dòng)態(tài)切換的方法

    這篇文章主要介紹了android編程實(shí)現(xiàn)局部界面動(dòng)態(tài)切換的方法,以實(shí)例形式較為詳細(xì)的分析了Android局部切換的布局及功能實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-11-11
  • Android Studio應(yīng)用開發(fā)集成百度語(yǔ)音合成使用方法實(shí)例講解

    Android Studio應(yīng)用開發(fā)集成百度語(yǔ)音合成使用方法實(shí)例講解

    這篇文章主要介紹了Android Studio應(yīng)用開發(fā)集成百度語(yǔ)音合成使用方法實(shí)例講解的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2016-11-11
  • 如何自己實(shí)現(xiàn)Android View Touch事件分發(fā)流程

    如何自己實(shí)現(xiàn)Android View Touch事件分發(fā)流程

    這篇文章主要介紹了如何自己實(shí)現(xiàn)Android View Touch事件分發(fā)流程,幫助大家更好的理解和學(xué)習(xí)使用Android,感興趣的朋友可以了解下
    2021-03-03
  • Android啟動(dòng)優(yōu)化之延時(shí)加載的步驟詳解

    Android啟動(dòng)優(yōu)化之延時(shí)加載的步驟詳解

    這篇文章主要給大家介紹了關(guān)于Android啟動(dòng)優(yōu)化之延時(shí)加載的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-02-02

最新評(píng)論