1. android如何让ScrollView的滚动条定位到最后一行
单独定义一个静态方法,建立一个线程判断滚动条的内层外层高度变化。
ScrollView
scrollresult=(ScrollView)findViewById(R.id.scrollView);
scroll2Bottom(scrollresult,
txthistroycontent);//txthistroycontent为滚动条关联的文本框
public
static
void
scroll2Bottom(final
ScrollView
scroll,
final
View
inner)
{
Handler
handler
=
new
Handler();
handler.post(new
Runnable()
{
@Override
public
void
run()
{
//
TODO
Auto-generated
method
stub
if
(scroll
==
null
||
inner
==
null)
{
return;
}
//
内层高度超过外层
int
offset
=
inner.getMeasuredHeight()
-
scroll.getMeasuredHeight();
if
(offset
<
0)
{
System.out.println("定位...");
offset
=
0;
}
scroll.scrollTo(0,
offset);
}
});
}
}
2. 如何动态测量ListView的高度
item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="
android:layout_width="wrap_content"
android:layout_height="44dp"
android:paddingLeft="10dp"
android:background="@color/white"
android:descendantFocusability="blocksDescendants"
android:paddingBottom="1dp">
android:id="@+id/tv_contact_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/iv_contact_photo"
android:textColor="@color/black" />
android:id="@+id/iv_contact_photo"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_margin="5dp" />
在使用此listView的布局中设置属性
<ListView
android:id="@+id/lv_addEventContact"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbarSize="0dp"
android:dividerHeight="0dp"
android:visibility="gone"
/>
定义一个函数将dp转换为像素
public int Dp2Px(Context context, float dp) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
定义函数动态控制listView的高度
public void (ListView listView) {
//获取listview的适配器
ListAdapter listAdapter = listView.getAdapter();
//item的高度
int itemHeight = 46;
if (listAdapter == null) {
return;
}
int totalHeight = 0;
for (int i = 0; i < listAdapter.getCount(); i++) {
totalHeight += Dp2Px(getApplicationContext(),itemHeight)+listView.getDividerHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight;
listView.setLayoutParams(params);
}
在每次listView的adapter发生变化后,要调用(listView)更新界面
3. 如何让ScrollView 的滚动条不显示
正好也遇到这个问题,刚看到的分享下
android:background 设置背景色/背景图片。可以通过以下两种方法设置背景为透明:”@android:color/transparent”和”@null”。注意TextView默认是透明的,不用写此属性,但是Buttom/ImageButton/ImageView想透明的话就得写这个属性了。
android:clickable 是否响应点击事件。
android:contentDescription 设置View的备注说明,作为一种辅助功能提供,为一些没有文字描述的View提供说明,如ImageButton。这里在界面上不会有效果,自己在程序中控制,可临时放一点字符串数据。
android:drawingCacheQuality 设置绘图时半透明质量。有以下值可设置:auto(默认,由框架决定)/high(高质量,使用较高的颜色深度,消耗更多的内存)/low(低质量,使用较低的颜色深度,但是用更少的内存)。
android:plicateParentState 如果设置此属性,将直接从父容器中获取绘图状态(光标,按下等)。 见下面代码部分,注意根据目前测试情况仅仅是获取绘图状态,而没有获取事件,也就是你点一下LinearLayout时Button有被点击的效果,但是不执行点击事件。
android:fadingEdge 设置拉滚动条时 ,边框渐变的放向。none(边框颜色不变),horizontal(水平方向颜色变淡),vertical(垂直方向颜色变淡)。参照fadingEdgeLength的效果图
android:fadingEdgeLength 设置 边框渐变的长度。
android:fitsSystemWindows 设置布局调整时是否考虑系统窗口(如状态栏)
android:focusable 设置是否获得焦点。若有requestFocus()被调用时,后者优先处理。注意在表单中想设置某一个如EditText获取焦点,光设置这个是不行的,需要将这个EditText前面的focusable都设置为false才行。在Touch模式下获取焦点需要设置focusableInTouchMode为true。
android:focusableInTouchMode 设置在Touch模式下View是否能取得焦点。
android:hapticFeedbackEnabled 设置长按时是否接受其他触摸反馈事件。这里模拟器没有试出效果,难道是多点触摸?找不到资料可以找找performHapticFeedback或HapticFeedback这个关键字的资料看看。
android:id 给当前View设置一个在当前layout.xml中的唯一编号,可以通过调用View.findViewById() 或Activity.findViewById()根据这个编号查找到对应的View。不同的layout.xml之间定义相同的id不会冲突。格式如”@+id/btnName”
android:isScrollContainer 设置当前View为滚动容器。这里没有测试出效果来,ListView/ GridView/ ScrollView根本就不用设置这个属性,而EdidText设置android:scrollbars也能出滚动条。
android:keepScreenOn View在可见的情况下是否保持唤醒状态。
常在LinearLayout使用该属性,但是模拟器这里没有效果。
android:longClickable 设置是否响应长按事件.
android:minHeight 设置视图最小高度
android:minWidth 设置视图最小宽度度
android:nextFocusDown 设置下方指定视图获得下一个焦点。焦点移动是基于一个在给定方向查找最近邻居的算法。如果指定视图不存在,移动焦点时将报运行时错误。可以设置imeOptions= actionDone,这样输入完即跳到下一个焦点。
android:nextFocusLeft 设置左边指定视图获得下一个焦点。
android:nextFocusRight 设置右边指定视图获得下一个焦点。
android:nextFocusUp 设置上方指定视图获得下一个焦点。
android:onClick 点击时从上下文中调用指定的方法。这里指定一个方法名称,一般在Activity定义符合如下参数和返回值的函数并将方法名字符串指定为该值即可:
public void onClickButton(View view)
android:onClick=” onClickButton”
android:padding 设置上下左右的边距,以像素为单位填充空白。
android:paddingBottom 设置底部的边距,以像素为单位填充空白。
android:paddingLeft 设置左边的边距,以像素为单位填充空白。
android:paddingRight 设置右边的边距,以像素为单位填充空白。.
android:paddingTop 设置上方的边距,以像素为单位填充空白。
android:saveEnabled 设置是否在窗口冻结时(如旋转屏幕)保存View的数据,默认为true,但是前提是你需要设置id才能自动保存,参见这里。
android:scrollX 以像素为单位设置水平方向滚动的的偏移值,在GridView中可看的这个效果。
android:scrollY 以像素为单位设置垂直方向滚动的的偏移值
android: 设置是否始终显示垂直滚动条。这里用ScrollView、ListView测试均没有效果。
android: 设置是否始终显示垂直滚动条。这里用ScrollView、ListView测试均没有效果。
android: 设置N毫秒后开始淡化,以毫秒为单位。
android:scrollbarFadeDuration 设置滚动条淡出效果(从有到慢慢的变淡直至消失)时间,以毫秒为单位。Android2.2中滚动条滚动完之后会消失,再滚动又会出来,在1.5、1.6版本里面会一直显示着。
android:scrollbarSize 设置滚动条的宽度。
android:scrollbarStyle 设置滚动条的风格和位置。设置值:insideOverlay、insideInset、outsideOverlay、outsideInset。这里没有试出太多效果,以下依次是outsideOverlay与outsideInset效果截图比较:
android:scrollbarThumbHorizontal 设置水平滚动条的drawable(如颜色)。
android:scrollbarThumbVertical 设置垂直滚动条的drawable(如颜色).
android:scrollbarTrackHorizontal 设置水平滚动条背景(轨迹)的色drawable(如颜色)
android:scrollbarTrackVertical 设置垂直滚动条背景(轨迹)的drawable注意直接设置颜色值如”android:color/white”将得出很难看的效果,甚至都不理解这个属性了,这里可以参见ApiDemos里res/drawable/ scrollbar_vertical_thumb.xml和scrollbar_vertical_track.xml,设置代码为:android:scrollbarTrackVertical ="@drawable/scrollbar_vertical_track"
android:scrollbars 设置滚动条显示。none(隐藏),horizontal(水平),vertical(垂直)。见下列代码演示使用该属性让EditText内有滚动条。但是其他容器如LinearLayout设置了但是没有效果。
android:soundEffectsEnabled 设置点击或触摸时是否有声音效果
android:tag 设置一个文本标签。可以通过View.getTag()或 for with View.findViewWithTag()检索含有该标签字符串的View。但一般最好通过ID来查询View,因为它的速度更快,并且允许编译时类型检查。
android:visibility 设置是否显示View。设置值:visible(默认值
4. Android 滚动条 ProgressBar 怎么停止
如果把内容包含在ScrollView中,当内容超出高度时会自动出现滚动条。
另外,使用控件HorizontalScrollView 来包住内容时,
如果内容假设是一个LinearLayout, 那么当LinearLayout的宽度超过屏幕时, 将会自动产生滚动条,当拖动鼠标时,效果跟scrollView一样,不过是横向而己
5. android scrollview的水平滚动条问题,哪位高手给指教下啊,谢谢了!!
如果你把内容包含在ScrollView中,当内容超出高度时会自动出现滚动条。
另外,使用控件HorizontalScrollView 来包住你的内容时,
如果你的内容假设是一个LinearLayout, 那么当LinearLayout的宽度超过屏幕时, 将会自动产生滚动条,当你拖动鼠标时,效果跟scrollView一样,不过是横向而己
例:
纵向滚动
<ScrollView>
<LinearLayout ........>
<TextView ...../>
<TextView ...../>
<TextView ...../>
<TextView ...../>
</LineraLayout>
</ScrollView>
模向滚动
<HorizontalScrollView >
<LinearLayout ........>
<TextView ...../>
<TextView ...../>
<TextView ...../>
<TextView ...../>
</LineraLayout>
</HorizontalScrollView >
有时候甚至可以做到横向纵向都支持,只需要你合理设计就可以, 注意ScrollView中只能加一个控制,不能超过两个
6. 滚动条按钮的高度怎么设置scrollbar-track-piece
vb适当设置滚动条的大小和位置通过以下参数实现: 说明;滚动条控件(ScrollBar)分为水平滚动条(HScrollbar)和垂直滚动条(VscrollBar)二种,通常附在窗体上协助观察数据或确定位置,也可用作数据输入工具,用来提供某一范围内的数值供用户...
7. android 怎样让滚动条长度随着文本内容变化而变化
明白楼主想干嘛了.
一个TextView,显示从xml里读出来的数据,因为可能数据量比较大,TextView显示不下.
其实TextView没有你说的功能,但你想要做到很简单,在最外层套一个ScrollView就好了,显示不下就会有滚动条了.
8. android TextView滚动条设置android:ellipsize="marquee" android:scrollbars="horizontal" android:marqu
1.你滚动条包含的列表项要超过页面显示范围
2.mxl代码中多所有的列表项都要包含在scroll中。(也就是scroll要把列表项括起来)
随便给你段代码 scroll里面的内容不用仔细看,就是一些列表组件什么的。注意sroll的格式就好了
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#ff888888">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff888888">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#ff888888">
<TextView android:layout_width="wrap_content" android:id="@+id/Text" android:layout_height="wrap_content" android:text="@string/title" android:layout_gravity="center" android:textColor="#ffff00ff" android:textSize="30sp" android:layout_marginBottom="10px" android:layout_marginTop="30px"></TextView>
<Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:text="@string/backlight" android:id="@+id/backlight"></Button><Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:id="@+id/screen" android:text="@string/screen"></Button><Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:id="@+id/speaker" android:text="@string/speaker"></Button><Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:id="@+id/headset" android:text="@string/headset"></Button>
<Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:text="@string/vibrator" android:id="@+id/vibrator"></Button>
<Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:id="@+id/battery" android:text="@string/battery"></Button><Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:text="@string/dial" android:id="@+id/dial"></Button><Button android:gravity="left" android:layout_width="fill_parent" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:id="@+id/fingerpaint" android:text="@string/fingerpaint"></Button>
<Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:text="@string/touchpanel" android:id="@+id/touchpanel"></Button><Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:text="@string/gsensor" android:id="@+id/gsensor"></Button><Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:id="@+id/camera" android:text="@string/camera"></Button><Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:id="@+id/wifi" android:text="@string/wifi"></Button>
<Button android:id="@+id/picture" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:layout_width="fill_parent" android:text="@+string/picture"></Button><Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:id="@+id/bluetooth" android:text="@string/bluetooth"></Button><Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:id="@+id/keypress" android:text="@string/keypress"></Button><Button android:id="@+id/locateme" android:text="GPS" android:layout_width="fill_parent" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:gravity="left"></Button>
</LinearLayout>
</ScrollView>
</LinearLayout>
9. 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); }
10. android中设置的垂直滚动条,当图片在放大之后,图片上端有一部分显示不了,下面可以全部显示
你把scrollView的 android:layout_centerVertical="true" 和下面水平 ="true" 换成
android:gravity="centerVertical|centerHorizontal" layout_center... 说的是他自己本身