deliaandroid
動態改變控件的方法app
1.聲明控件參數獲取的對象佈局
LinearLayout.LayoutParams linear = (LayoutParams) view.getLayoutParams();post
2.設置控件參數,如寬度:動畫
linear.width = 10;spa
3.使得設置生效對象
view.setLayoutParams(linear);ip
注意:view表示的是對應的控件對象開發
posted @ 2012-03-01 11:29 delia 閱讀(5) 評論(0) 編輯get
讓TextView 自帶滾動條
TextView中有個ellipsize屬性,做用是當文字過長時,該控件該如何顯示,解釋以下:
1.android:ellipsize=」start」—–省略號顯示在開頭
2.android:ellipsize=」end」——省略號顯示在結尾
3.android:ellipsize=」middle」—-省略號顯示在中間
4.android:ellipsize=」marquee」–以跑馬燈的方式顯示(動畫橫向移動)
文字左右滾動三個屬性:
android:singleLine=」true」
android:ellipsize=」marquee」
android:marqueeRepeatLimit=」marquee_forever」
Android中咱們爲了實現文本的滾動能夠在ScrollView中嵌入一個TextView,其實TextView本身也能夠實現多行滾動的,畢竟 ScrollView必須只能有一個直接的子類佈局。只要在layout中簡單設置幾個屬性就能夠輕鬆實現。
<TextView
android:id=」@+id/tvCWJ」
android:layout_width=」fill_parent」
android:layout_height=」wrap_content」
android:scrollbars=」vertical」 <!–垂直滾動條 –>
android:singleLine=」false」 <!–實現多行 –>
android:maxLines=」15″ <!–最多不超過15行 –>
android:textColor=」#FF0000″
/>
< TextView
android:id = 」@+id/app_shortcontent」
android:layout_width = 」wrap_content」
android:layout_height = 」wrap_content」
android:singleLine = 」true」
android:textColor = 」#FFFFFFFF」
android:scrollHorizontally = 」true」
android:focusable = 」true」
android:ellipsize = 」marquee」
android:marqueeRepeatLimit = 」marquee_forever」 />
固然咱們爲了讓TextView動起來,還須要用到TextView的setMovementMethod方法設置一個滾動實例,代碼以下
TextView tv = (TextView)findViewById(R.id.tvCWJ);
tv.setMovementMethod(ScrollingMovementMethod.getInstance()); // Android開發網提示相關的能夠查看SDK中android.text.method分支瞭解更多
附:
順便講下 TextView 自動滾動的實現方法,下面介紹兩種方法:
1、在代碼中實現:
textView .setEllipsize(TextUtils.TruncateAt.MARQUEE);
textView .setSingleLine(true);
textView .setMarqueeRepeatLimit(6);
2、在XML中實現:
<TextView android:id=」@+id/TextView01″ android:layout_width=」wrap_content」
android:layout_height=」wrap_content」 android:singleLine=」true」
android:text=」dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd」
android:marqueeRepeatLimit=」marquee_forever」 android:ellipsize=」marquee」
android:scrollHorizontally=」true」 android:width=」150dip」></TextView>
一切OK,當 textView 獲取焦點後,就會自動滾動。
補充 ==============================
無論是手動仍是自動 你要實現滾動就得加scrollview
到時候能夠經過handle來調用scrollview的scrollTo方法實現滾動
Handler mHandler = new Handler();
private Runnable mScrollToBottom = new Runnable() {
public void run() {
mScrollView.scrollTo(0, offset);
}
};
onTouch裏面
mHandler.post(mScrollToBottom);
補充 ====================
補充:
1,把 textview的 Ellipsize 設置成 marquee(上面有說)
2,把 Deprecated的 Single line 設置成 true
3,設置textview的Marquee repeat limit 屬性(滾動回數,默認是無數回)
貼個代碼吧.
textview.setEllipsize(TextUtils.TruncateAt.MARQUEE);
textview.setSingleLine(true);
textview.setMarqueeRepeatLimit(6);