1.TextView
(1)文字加粗及陰影效果
android:textStyle="bold" 加粗,還可以設置爲italic,斜體形式
陰影效果實現需要四個參數
android:shadowColor="@color/colorAccent" 陰影顏色
android:shadowDx="10" x方向偏移
android:shadowDy="10" y方向偏移
android:shadowRadius="1" 陰影半徑
(2)顯示文字及圖片
之前我一直用ImageView和TextView結合使用實現這個效果,但那樣就會嵌套一些佈局來輔助實現,比較複雜
android:drawableLeft="@mipmap/ic_launcher_round"//在文本框內文本左端指定圖像
android:drawableRight //在文本框內文本右端指定圖像
android:drawableTop //在文本框內文本頂端指定圖像
android:drawableBottom //在文本框內文本底端指定圖像
android:drawablePadding="10dp"//設置文本框內文字與圖片的距離
(3)跑馬燈
一行文本內容太多,不想多行顯示,可以設置一種文本從左到右滾動的效果,類似於跑馬燈
<TextView
android:layout_alignParentRight="true"
android:id="@+id/hello"
android:text="@string/test"
android:textSize="20dp"
android:layout_margin="10dp"//設置兩邊的留白均爲10dp
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"//這個很關鍵,以下代碼不設置會有截斷省略效果
android:ellipsize="marquee"//設置當文字過長時,該控件該如何顯示。有如下值設置:”start”—-省略號顯示在開頭;”end” ——省略號顯示在結尾;”middle”—-省略號顯示在中間;
android:marqueeRepeatLimit="marquee_forever"//與上一句合起來無限輪播
android:scrollHorizontally="true"//橫向滾動
android:focusable="true" //後面這兩句不加不會滾動
android:focusableInTouchMode="true"
/>
跑馬燈啓動需要條件:
1)單行顯示,且字數超過15;
2)獲取焦點android:focusable=“true” android:focusableInTouchMode=“true”
3)水平可滾動
4)循環android:marqueeRepeatLimit=“marquee_forever”
可以設置爲非0的數,效果一樣的。如果是0,呈現的是最後一個字半透明截斷效果