日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

addStatesFromChildren 和跑馬燈 - java - JavaEye技術(shù)網(wǎng)站

 shaobin0604@163.com 2010-09-11

在Android中要顯示跑馬燈是比較容易的,只要設(shè)置2個(gè)屬性就可以了:
android:singleLine="true"
android:ellipsize="marquee"

但 是要顯示跑馬燈該View必需是可以取得焦點(diǎn)的,只有在取得焦點(diǎn)的情況下跑馬燈才會(huì)出現(xiàn).
如果是組合View的情況下就有問(wèn)題了, 如下一個(gè)組合View:

<? xml version="1.0" encoding="utf-8" ?>
< LinearLayout
   xmlns:android ="http://schemas./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個(gè)TextView組合為一個(gè)View,由于設(shè)置了LinearLayout為focusable而TextView就沒(méi)法取得焦點(diǎn)了,這樣 這個(gè)TextView的跑馬燈效果就顯示不出來(lái),就算你也設(shè)置TextView的 android:focusable= "true" 也是 沒(méi)用的. 這個(gè)時(shí)候就要使用addStatesFromChildren 這個(gè)屬性了,在LinearLayout中設(shè)置這個(gè)屬性,然后設(shè)置TextView的focusable= "true" 就可以了.關(guān)于 addStatesFromChildren的說(shuō)明:

Sets whether this ViewGroup's drawable states also include its children's drawable states.

可以正常顯示的代碼:

<? xml version="1.0" encoding="utf-8" ?>
< LinearLayout
   xmlns:android ="http://schemas./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 >

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶(hù)發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約