TextView 详解一

来源:互联网 发布:韩国女演员排行知乎 编辑:程序博客网 时间:2024/06/06 14:07
<?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