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);
        }
    
    }
  • 相关阅读:
    [转载]windows进程中的内存结构
    RTTI和4个强制转换运算符
    由于应用程序配置不正确,程序未能启动
    光照
    服务器数据同步
    SAP
    PHP输入流php://input
    五款常用mysql slow log分析工具的比较
    开发搜索引擎–PHP中文分词
    大型网站调试工具之一(php性能优化分析工具XDebug)
  • 原文地址:https://www.cnblogs.com/androidsuperman/p/3460723.html
Copyright © 2011-2022 走看看