亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android開發(fā)手冊TextView控件及陰影效果實(shí)現(xiàn)

 更新時(shí)間:2022年06月11日 09:04:06   作者:芝麻粒兒  
這篇文章主要為大家介紹了Android開發(fā)手冊TextView控件及陰影效果的實(shí)現(xiàn)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

TextView是Android中最簡單也是最常見的控件。今天小空就帶大家會會她。

??實(shí)踐過程

??初識

經(jīng)過前兩篇常用屬性和不常用屬性的講解,是不是有些懵了,不要慌,真實(shí)開發(fā)中用到的屬性其實(shí)連五分之一都到不了。

我們先來創(chuàng)建個(gè)基本的文本控件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".TextActivity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:text="愛是一道光,綠到你發(fā)慌"
        android:textColor="#00ff00"
        android:textSize="20sp" />
</RelativeLayout>

結(jié)合上面屬性列表,運(yùn)行效果是這樣的:

那上面代碼寫的對嗎?

對,一點(diǎn)都沒錯(cuò),否則怎么能看到效果了。

那還有更好的方式嗎?

有,就是將text和textColor提出來,放到專門的文件里,text在【res-values-strings.xml中】,textColor在【res-values-colors.xml】中。

那么我們這么做的好處是什么呢?

你想象下有這么個(gè)場景:不同的頁面都有相同的文本,在不同的頁面布局有對應(yīng)的TextView,這就存在多個(gè)text,當(dāng)有一天需要修改這個(gè)文本的時(shí)候,你難道每個(gè)文本都改一遍(其實(shí)完全可以)?但是如果我們把text提出到【strings.xml】中,所有頁面都能引用,以后遇見修改只需要修改【strings.xml】中的那一個(gè)文本就行了。

這就是文本配置文件,同理color是在顏色配置文件中【colors.xml】。

解決國際化需求也只需要再提供一個(gè)英文的【string.xml】即可。

??文字陰影

某天,產(chǎn)品經(jīng)理過來提需求了:小空啊,文本看起來一般啊,咱能更強(qiáng)大些嗎?比如,立體些,你知道的,那樣更有吸引力。

小空不搭理他,直接反手就是代碼,必須要用該屬性秀他一臉。

  • android:shadowColor:設(shè)置陰影顏色
  • android:shadowRadius:設(shè)置陰影模糊程度,必須要有該屬性
  • android:shadowDx :設(shè)置陰影在水平方向的偏移,向右為正,向左為負(fù)
  • android:shadowDy:設(shè)置陰影在豎直方向的偏移,向下為正,向上為負(fù)
<TextView
    android:id="@+id/myTest"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_centerInParent="true"
    android:layout_gravity="bottom"
    android:gravity="center"
    android:text="@string/test"
    android:textStyle="normal"
    android:shadowColor="#ff0000"
    android:shadowRadius="10"
    android:shadowDx="20"
    android:shadowDy="20"
    android:textColor="@color/green"
    android:textSize="26sp" />

以上就是Android開發(fā)手冊TextView控件及陰影效果實(shí)現(xiàn)的詳細(xì)內(nèi)容,更多關(guān)于Android開發(fā)TextView控件陰影效果的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論