androidUI设计之旅 ----TextView01

      这个适合有android基础的同学学习,再次感谢那些在网上实现数据共享的大牛们,让我们这些菜鸟快速成长。

    UI设计,类似于美工,手机上设计出一个漂亮的界面,会增加很多的用户量,假设你的系统的做的特别的好,那么你的UI应该很是精美。

 (1)实现TextView的字体,大小,颜色,URL等设计  

     我们要实现这样一个效果:

androidUI设计之旅 ----TextView01_第1张图片

        作为菜鸟的我,看到这个运行效果的时候,我激动的直到,我开始做UI设计了,我的知识领域又宽了。回想以前自己做的界面很是单调,很多自带的属性也没有弄明白,只是了解那个几个常用的数性,现在我们做了UI设计,那么我们就要了解所有的相关属性,也许你做不到全部都熟识精通,但是我们要做到,我们认识它,直到它是干什么的。

今天,我们要学习的是如何设置字体,如何使用html设计,如何实现两种不同的链接方式。好了,我们的学习之旅开始了。

(2)如何实现。

   在布局文件里,mian.xml文件了写三个TextView空间,并设置相关属性,不废话了,上代码。

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <TextView
        android:id="@+id/textview1"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:text="@string/phone" >
    </TextView>

    <TextView
        android:id="@+id/textview2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="20dp"
        android:textColor="@color/green"
        android:textSize="20sp" />

    <TextView
        android:id="@+id/textview3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:autoLink="all"
        android:padding="20dp" />

</LinearLayout>

    textview1,2,3三id是为了我们找到他们。还有很多xml属性,android:layout_width ,android:textcolor等等,稍后补充。

 (3)主文件MainActvity

 

public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		textView1 = (TextView) findViewById(R.id.textview1);
		textView2 = (TextView) findViewById(R.id.textview2);
		textView3 = (TextView) findViewById(R.id.textview3);
		textView1.setMovementMethod(LinkMovementMethod.getInstance());
		String html="<font color='red'><big>I love android</big></font>";
		html+="<font color='#00FF00'><small><i><a href='http://www.baidu.com'>我爱这个充满挑战的社会</a></i></small></font>";
        CharSequence charSequence = Html.fromHtml(html);
        textView2.setText(charSequence);
        textView2.setMovementMethod(LinkMovementMethod.getInstance());
        String textString="百度查询:http://baidu.com\n";
        textString+="我的电话是: 012345678901\n";
        textString+="[email protected]\n";
        textView3.setText(textString);
        textView3.setMovementMethod(LinkMovementMethod.getInstance());
	}


 这里:我主要要掌握CharSequence和setMovementMethod

你可能感兴趣的:(androidUI设计之旅 ----TextView01)