android橫向滾動條
⑴ android scrollview的水平滾動條問題,哪位高手給指教下啊,謝謝了!!
如果你把內容包含在ScrollView中,當內容族稿超出高度時會自動出現滾動條。
另外,使用控制項HorizontalScrollView 來包住你的內容時,兆寬孝
如果你的內容假設是一個LinearLayout, 那麼當LinearLayout的寬度超過屏幕時, 將會自動產生滾動條,當你拖動滑鼠時,效果跟scrollView一樣,不過是橫向而己
例:
縱向滾動
<ScrollView>
<LinearLayout ........>
<TextView ...../>
<TextView ...../>
<TextView ...../>
<TextView ...../>
</LineraLayout>
</ScrollView>
模向滾動
<HorizontalScrollView >
<LinearLayout ........>
<TextView ...../>
<TextView ...../>
<TextView ...../>
<TextView ...../巧寬>
</LineraLayout>
</HorizontalScrollView >
有時候甚至可以做到橫向縱向都支持,只需要你合理設計就可以, 注意ScrollView中只能加一個控制,不能超過兩個
⑵ android 我在textview中設置了滾動條
layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ScrollView
android:id="@+id/sv"
android:layout_width="match_parent"
android:layout_height="150dp"
android:fadingEdge="vertical"
android:scrollbars="vertical" >
<TextView
android:id="@+id/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text=""
android:textSize="18sp" />
</ScrollView>
</RelativeLayout>
activity:
ScrollView sv = (ScrollView)this.findViewById(R.id.sv);
sv.setOnTouchListener(new OnTouchListener() {
@SuppressLint("NewApi")
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
height = event.getY();
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
height = event.getY()-height;
if(height>=0){
Toast.makeText(MainActivity.this, "本次向下拉動了"+height, Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(MainActivity.this, "本次向上拉動了:"+Math.abs(height), Toast.LENGTH_SHORT).show();
}
break;
}
return false;
}
});
⑶ 如何實現android中橫向滾動的gridView
法1.直接用tablelayout gridview是根據你每行的單元數自動生成的行數;
法2.可以在代碼里根據view數來動態設置列數,比如有10記錄可以設置列數為10/3+1,這樣就有三行四列了。
如果您對我的回答有不滿意的地方,還請您繼續追問;
答題不易,互相理解,互相幫助!
⑷ android實現上下滑動
布局最外包一層滾動條
java"><ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
強制橫豎屏
在配置文件中對Activity節點添加android:screenOrientation屬性(landscape是橫向,portrait是縱向)
⑸ android 如何給listview添加橫向滾動條,網上說的在listview外層加horizontalscrollview沒有用啊
誰說沒用,親測可以
xml布局裡寫:
<HorizontalScrollView
android:layout_width="200dp"
android:layout_height="fill_parent">
<ListView
android:layout_width="400dp"
android:layout_height="fill_parent"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
android:scrollingCache="false"
/>
</HorizontalScrollView>
一個橫向滾動且縱向滾動的listView不就出來了
⑹ android文字橫向滾動的自定義view
TextView實現文字滾動需要以下幾個要點: 1.文字長度長於可顯示範圍:android:singleLine=」true」 2.設置可滾到,或顯示樣式
TextView實現文字滾動需要以下幾個要點:
1.文字長度長於可顯示範圍:android:singleLine=」true」
2.設置可滾到,或顯示樣式:android:ellipsize=」marquee」
3.TextView只有在獲取焦點後才會滾動顯示隱藏文字,因此需要在包中新建一個類,繼承TextView。重寫isFocused方法,這個方法默認行為是,如果TextView獲得焦點,方法返回true,失去焦點則返回false。跑馬燈效果估計也是用這個方法判斷是否獲得焦點,所以把它的返回值始終設置為true。
自定義一個
AlwaysMarqueeTextView 類
public class AlwaysMarqueeTextView extends TextView { public AlwaysMarqueeTextView(Context context) { super(context); } public AlwaysMarqueeTextView(Context context, AttributeSet attrs) { super(context, attrs); } public AlwaysMarqueeTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public boolean isFocused() { return true; }
在布局XML文件中加入這么一個AlwaysMarqueeTextView,這個加入方法也是剛剛學的。
<com.examples.AlwaysMarqueeTextView android:id=「@+id/AMTV1″ android:layout_width=「fill_parent」 android:layout_height=「wrap_content」 android:lines=「1″ android:focusable=「true」 android:focusableInTouchMode=「true」 android:scrollHorizontally=「true」 android:marqueeRepeatLimit=「marquee_forever」 android:ellipsize=「marquee」 android:background=「@android:color/transparent」 />
ellipsize屬性
設置當文字過長時,該控制項該如何顯示。有如下值設置:」start」—–省略號顯示在開頭;」end」——省略號顯示在結尾;」middle」—-省略號顯示在中間;」marquee」 ——以跑馬燈的方式顯示(動畫橫向移動)
marqueeRepeatLimit屬性
在ellipsize指定marquee的情況下,設置重復滾動的次數,當設置為marquee_forever時表示無限次。
focusable屬性
自己猜測的,應該是能否獲得焦點,同樣focusableInTouchMode應該是滑動時能否獲得焦點。
組合View的問題:
< 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 繪制進度條
進度條一般是用來顯示耗時操作的,如你圖示,最終完成的時候剛好繞一圈,是一個計時器來確定進度條跑完一圈的時間,然後按時間的流逝來繪制進度條(也就是邊框)。
我的思路是這樣的,首先確定進度條的起始位置,也就是黑色背景圖的上部中間(前提是獲取到背景圖片四個角角位置坐標(X,Y)),計算出圖片的長寬,這樣背景圖片四個角的坐標都有了,進度條的起始坐標也有了,然後根據周長和定時器的時間確定我們每毫秒需要繪制多長,遇到拐角的時候判斷一下進度條的實時坐標與背景圖的拐角坐標是否一致,然後就拐個彎,繼續繪制。
這是個思路,我過會兒調試一下
⑻ android中怎樣設置滾動條
mThumbDrawable 這個文件沒有,根本為崩潰; 並不是方法不好用,是你沒有抄全; 在實際應用中,該代碼會出現異常,通過對幾個sdk源碼的對比,發現Google會對其中的屬性做一些微調: 如在5.x中,「mFastScroller」改為了「mFastScroll」,4.4中則把「mThumbDrawable」改為「thumbDrawable」並設為了final,在5.x中又恢復成了private. 所以在實際應用中還需加以判斷。下面是針對4.4修改後的代碼: 由於class FastScroller沒有public屬性,無法直接導包獲取到,所以從用到該類的AbsListView中獲取。 try { Field f = AbsListView.class.getDeclaredField("mFastScroller"); //獲取AbsListView中的屬性mFastScroller f.setAccessible(true);//設置屬性可修改 Object o = f.get(listview);//得到listview實例 // Field[] fields = f.getType().getDeclaredFields(); // for (Field field : fields) { // Log.v("TAG", field.getName()); // } //查看所有屬性名 f = f.getType().getDeclaredField("mThumbImage");//獲取屬性mThumbImage(由於 4.4中的thumbDrawable不可修改,所以直接取其imageview) f.setAccessible(true); ImageView img = (ImageView) f.get(o); //得到ImageView實例 img.setImageDrawable(getResources().getDrawable(R.drawable.icon)); f.set(o, img); //把編輯好的ImageView放進去 } catch (Exception e) { throw new RuntimeException(e); }