TextView跑馬燈效果與addStatesFromChildren屬性關係
在Android中要顯示跑馬燈是比較容易的,只要設定2個屬性就可以了:
android:singleLine="true"
android:ellipsize="marquee"
但 是要顯示跑馬燈該View必需是可以取得焦點的,只有在取得焦點的情況下跑馬燈才會出現.
如果是組合View的情況下就有問題了, 如下一個組合View:
<!-- <br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><? xml version="1.0" encoding="utf-8" ?>
< LinearLayout
xmlns:android ="http://schemas.android.com/apk/res/android"
android:orientation ="vertical"
android:gravity ="center_vertical"
android:background ="@drawable/f_background"
android:layout_width ="fill_parent"
android:focusable ="true"
android:layout_height ="50px" >
< TextView
android:id ="@+id/info_text"
android:focusable ="true"
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:text ="test marquee .. "
android:textColor ="@color/black"
android:singleLine ="true"
android:ellipsize ="marquee"
android:marqueeRepeatLimit ="3"
android:textSize ="18sp"
/>
< TextView
android:id ="@+id/date_text"
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:layout_gravity ="bottom"
android:textColor ="@color/gray"
android:text ="2010/05/28"
android:textSize ="12sp"
/>
</ LinearLayout >
< LinearLayout
xmlns:android ="http://schemas.android.com/apk/res/android"
android:orientation ="vertical"
android:gravity ="center_vertical"
android:background ="@drawable/f_background"
android:layout_width ="fill_parent"
android:focusable ="true"
android:layout_height ="50px" >
< TextView
android:id ="@+id/info_text"
android:focusable ="true"
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:text ="test marquee .. "
android:textColor ="@color/black"
android:singleLine ="true"
android:ellipsize ="marquee"
android:marqueeRepeatLimit ="3"
android:textSize ="18sp"
/>
< TextView
android:id ="@+id/date_text"
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:layout_gravity ="bottom"
android:textColor ="@color/gray"
android:text ="2010/05/28"
android:textSize ="12sp"
/>
</ LinearLayout >
上面示例中2個TextView組合為一個View,由於設定了LinearLayout為focusable而TextView就沒法取得焦點了,這樣 這個TextView的跑馬燈效果就顯示不出來,就算你也設定TextView的 android:focusable=
"true"
也是
沒用的. 這個時候就要使用addStatesFromChildren 這個屬性了,在LinearLayout中設定這個屬性,然後設定TextView的focusable=
"true"
就可以了.關於addStatesFromChildren的說明:
Sets whether
this
ViewGroup's
drawablestates
also include its children's drawablestates.
可以正常顯示的程式碼:
<!-- <br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> --><? xml version="1.0" encoding="utf-8" ?>
< LinearLayout
xmlns:android ="http://schemas.android.com/apk/res/android"
android:orientation ="vertical"
android:gravity ="center_vertical"
android:background ="@drawable/zixun_background"
android:layout_width ="fill_parent"
android:addStatesFromChildren ="true"
android:layout_height ="50px" >
< TextView
android:id ="@+id/info_text"
android:focusable ="true"
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:text =" "
android:textColor ="@color/black"
android:singleLine ="true"
android:ellipsize ="marquee"
android:marqueeRepeatLimit ="3"
android:textSize ="18sp"
/>
< TextView
android:id ="@+id/date_text"
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:layout_gravity ="bottom"
android:textColor ="@color/gray"
android:text ="2010/05/28"
android:textSize ="12sp"
/>
</ LinearLayout >
< LinearLayout
xmlns:android ="http://schemas.android.com/apk/res/android"
android:orientation ="vertical"
android:gravity ="center_vertical"
android:background ="@drawable/zixun_background"
android:layout_width ="fill_parent"
android:addStatesFromChildren ="true"
android:layout_height ="50px" >
< TextView
android:id ="@+id/info_text"
android:focusable ="true"
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:text =" "
android:textColor ="@color/black"
android:singleLine ="true"
android:ellipsize ="marquee"
android:marqueeRepeatLimit ="3"
android:textSize ="18sp"
/>
< TextView
android:id ="@+id/date_text"
android:layout_width ="fill_parent"
android:layout_height ="wrap_content"
android:layout_gravity ="bottom"
android:textColor ="@color/gray"
android:text ="2010/05/28"
android:textSize ="12sp"
/>
</ LinearLayout >
相關文章
- TextView跑馬燈效果,也就是,自動滾動文字的效果。TextView
- 影片直播原始碼,Android TextView設定跑馬燈效果原始碼AndroidTextView
- Swift跑馬燈效果Swift
- zeptojs-跑馬燈效果JS
- 公告欄跑馬燈效果程式碼
- TextView走馬燈TextView
- 跑馬燈帶你深入淺出TextView的原始碼世界TextView原始碼
- 微信小程式如何開發跑馬燈效果?微信小程式
- Flutter 跑馬燈Flutter
- flutter跑馬燈Flutter
- 【Android】不依賴焦點和選中的TextView跑馬燈AndroidTextView
- androidTextView實現簡單的跑馬燈效果AndroidTextView
- JavaFx 實現水平滾動文字(跑馬燈效果)Java
- 【Android】不依賴焦點和選中的TextView跑馬燈【2】AndroidTextView
- 用程式碼簡單的實現跑馬燈效果
- TextView屬性TextView
- VUE-文字跑馬燈Vue
- css自定義屬性和聚光燈效果CSS
- Vue實現跑馬燈效果以及封裝為元件釋出Vue封裝元件
- quotes屬性與<q>標籤關係
- HTMl 中marquee標籤實現無縫滾動跑馬燈效果HTML
- 簡單實現跑馬燈案例
- H5製作跑馬燈H5
- 最簡單的跑馬燈程式
- CSS 數學函式與容器查詢實現不定寬文字溢位跑馬燈效果CSS函式
- 結合 CSS3 transition transform 實現簡單的跑馬燈效果CSSS3ORM
- 用js寫的一個跑馬燈JS
- iOS 跑馬燈 之 TXScrollLabelViewiOSView
- JS 跑馬燈抽獎活動程式碼解析與優化(2)JS優化
- 前端實現文字跑馬燈的三種方式前端
- Flutter實現Android跑馬燈及滾動廣告FlutterAndroid
- iOS:一用就上癮的跑馬燈檢視iOS
- HarmonyOS NEXT應用開發之深色跑馬燈案例
- (4)8個led每0.5s閃爍(跑馬燈)
- STM32F767cubemx開發手記(1) 跑馬燈
- 戰鬥公式的演化與策略--屬性與公式的關係、減法公式與乘法公式公式
- jQuery的動畫效果可以應用與哪些屬性jQuery動畫
- STM32之GPIO及第一個STM32程式(跑馬燈)