TextView 详解一

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frame"
    android:orientation="vertical"
    android:background="@drawable/bg_01"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!--
    //设置带阴影效果的TextView

    shadowColor:设置阴影颜色,必须设置shadowRadius
    shadowRadius:设置阴影的模糊程度,设为0.1不变,一般为3.0
    shadowDx:设置阴影在水平方向的偏移
    shadowDy:设置阴影在竖直方向的偏移
    -->
    <TextView
        android:shadowColor="#ccd637"
        android:shadowRadius="3.0"
        android:shadowDx="5.0"
        android:shadowDy="5.0"
        android:gravity="center"
        android:text="TextView的阴影测试"
        android:textColor="#0c0c87"
        android:background="#968d8d"
        android:layout_width="200dp"
        android:layout_height="48dp" />


    <!--带图片的TextView-->
    <!--autoLink="all"
        需要:
        Drawable[] drawable = textView.getCompoundDrawables( ); 获得四个不同方向上的图片资源,数组元素依次是:左上右下的图片
        drawable[1].setBounds(80, 0, 80, 80); 调用setBounds设置左上右下坐标点
        textView.setCompoundDrawables(drawable[0]);TextView重新设置drawable数组
    -->
    <TextView
        android:drawableTop="@drawable/meizi_01"
        android:layout_marginLeft="50dp"
        android:layout_marginTop="20dp"
        android:shadowColor="#ccd637"
        android:shadowRadius="3.0"
        android:shadowDx="5.0"
        android:shadowDy="5.0"
        android:gravity="center"
        android:text="带图片"
        android:textColor="#0c0c87"
        android:background="#968d8d"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <!--autoLink属性识别链接类型-->
    <!--java代码:android:autoLink="all"的时候
        TextView textView = (TextView) findViewById(R.id.tv);
        textView.setMovementMethod(LinkMovementMethod.getInstance());
    -->
    <TextView
        android:id="@+id/tv"
        android:drawableTop="@drawable/meizi_01"
        android:layout_marginLeft="50dp"
        android:layout_marginTop="20dp"
        android:gravity="center"
        android:autoLink="web"
        android:text="www.baidu.com"
        android:textColor="#0c0c87"
        android:background="#968d8d"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <!--textView加载HTML 包括:显示不同的字体颜色,大小,字体,甚至是显示图片,或者链接-->
    <!--TextView支持HTML的标签有:-->
    <!--
        <font>:颜色和字体。
        <big>:字体大号
        <small>:字体小号
        <i><b>:斜体粗体
        <a>:连接网址
        <img>:图片
    -->
    <!--java代码
        TextView textView2 = (TextView)findViewById(R.id.tv1);
        String s = "<font color='blue'><b>百度一下-你就知道</b></font><br>";
        s += "<a href = 'http://www.baidu.com'>GO</a>";
        textView2.setText(Html.fromHtml(s));
        textView2.setMovementMethod(LinkMovementMethod.getInstance());
    -->
    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <!--加载图片-->
    <!--java
    
        TextView tv2 = (TextView) findViewById(R.id.tv2);
        String s1 = "图片:<img src = 'bg_03'/><br>";
        tv2.setText(Html.fromHtml(s1, new Html.ImageGetter() {
            @Override
            public Drawable getDrawable(String source) {
                Drawable draw = null;
                try {
                    Field field = R.drawable.class.getField(source);
                    int resourceId = Integer.parseInt(field.get(null).toString());
                    draw = getResources().getDrawable(resourceId);
                    draw.setBounds(20, 0, draw.getIntrinsicWidth(), draw.getIntrinsicHeight());
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return draw;
            }
        }, null));
    -->
    
    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:text=""
        android:layout_height="wrap_content" />

</LinearLayout>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小猿成长

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值