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); }