zoukankan      html  css  js  c++  java
  • 在TextView上显示图片信息

    布局文件

    <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/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="@string/hello_world" />
    
    </RelativeLayout>

    java代码实现:

    package com.wangfubin.textviewshowimage;
    
    import android.annotation.TargetApi;
    import android.app.Activity;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.os.Build;
    import android.os.Bundle;
    import android.text.Spannable;
    import android.text.SpannableString;
    import android.text.style.ImageSpan;
    import android.widget.TextView;
    
    @TargetApi(Build.VERSION_CODES.DONUT)
    public class MainActivity extends Activity {
        private TextView text;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            text = (TextView)findViewById(R.id.text);
            setimage1();
        }
        /**
         * 
         * @Title: setimage1 
         * @Description: TODO(使用ImageSpan对象在TextView组件中显示图片) 
         * @param     设定文件 
         * @return void    返回类型 
         * @throws
         */
        private void setimage1() {
            Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
            ImageSpan imageSpan = new ImageSpan(this,bitmap);
            SpannableString spannableString = new SpannableString("icon");
            spannableString.setSpan(imageSpan, 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            text.setText(spannableString);
        }
    
    }
  • 相关阅读:
    解密:腾讯如何打造一款实时对战手游
    哪是来的自尊心
    NODEJS 在Centos下面的自动启动
    nodejs的安装与配置
    基于Centos7+Nginx+Tomcat8的负载均衡服务器的搭建
    门店管理系统架构-(1)
    PHP 使用编码树,生成easyui中的tree样式
    Apache 打开网页的时候等待时间过长的解决方案
    Apache2.4开启GZIP功能
    Apache+Tomcat实现负载均衡
  • 原文地址:https://www.cnblogs.com/androidsuperman/p/3460723.html
Copyright © 2011-2022 走看看