1.TextView autoLink属性
TextView也支持电话和email超链接,当我们设置android:autoLink="phone"的时候,文本里的电话就会变成蓝色超链接形式,点击就会打开拨号界面等待你按通话键拨号,email也是同理。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:autoLink="phone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="faf111111faf11111111hhhttp://www.baidu.com" /> //电话就会变成蓝色超链接形式
<TextView
android:autoLink="email"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="2544795924@qq.com" /> //邮件变成蓝色的超链接
</LinearLayout>
2.当我们把 android:autoLink换成phone的时候发现网址不超连接了,换成email也是一样。难道我们不能一下子让网址,电话,email都超链接吗?答案是肯定的,这时候我们可以把 android:autoLink设置成all,这样里面的网址、电话和email就都可以超链接了。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:autoLink=“all"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="2544795924@qq.com" /> //邮件变成蓝色的超链接
</LinearLayout>
3.跑马灯效果。有时候我们要显示的文本较长,TextView不能完全显示,这时候可以通过这中跑马灯的方式让文本移动展示,达到了既不占用地方又能完全看到文本的全部内容
<?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"
>
<TextView
android:id="@+id/text_view"
android:autoLink="all"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="开放平台成网络淘金下一站11111111111 从圈地到吸纳盟友,除腾讯外,http://www.baidu.com百度、盛大、京东商城等互联网行业标杆目前都已推出了各自的开放平台。"
android:ellipsize="marquee" //ellipsize若为start则.....出现在前面,若为end.......出现在后面,若为middle.......在中间,若为marqueen就是跑马灯
android:focusable="true" //focusable若为false就不可以滚动了,但可以用鼠标拖动
android:marqueeRepeatLimit="marquee_forever" //永远滚动
android:focusableInTouchMode="true" //focusableInTouchMode若为false就不可以滚动了,但可以用鼠标拖动
android:singleLine="true" //单行显示
android:scrollHorizontally="true"/> //横拉条效果,没有的话会变两行
</LinearLayout>
以上设置在大部分情况下都会成功的展示跑马灯样式,但是在一些复杂的布局中就会看不到任何文字。比如我开发的Android应用“我团”,在展示团购详细信息页面,我自定义了一个标题栏让其显示团购的信息,想让其跑马灯的方式显示,但是使用了上述代码后看不到文字,其实是文字被撑下来的,这时候我们设置android:singleLine="true"以单行的方式展示就好了。所以请以后实现跑马灯效果的时候最好加上android:singleLine="true"单行展示。。
手动拖动滚动条快速滑动
只需在ListView中加入一个参数
android:fastScrollEnabled="true" android:focusable="true"
android的源代码如下:
在contacts_list_content.xml中:
<com.android.contacts.FocusRequestingListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fastScrollEnabled="true"
/>
而FocusRequestingListView 的源代码如下:
public class FocusRequestingListView extends ListView {
private boolean mFirstLayoutDone = false;
public FocusRequestingListView(Context context) {
super(context);
}
public FocusRequestingListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FocusRequestingListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
if (!mFirstLayoutDone) {
setFocusable(true);
requestFocus();
}
mFirstLayoutDone = true;
}
}
其实有用的就这么两句话,
if (!mFirstLayoutDone) {
setFocusable(true);
requestFocus();
}
mFirstLayoutDone = true;
说的意思就是在什么情况下设置focusable焦点。
很多开发者不知道ListView列表控件的快速滚动滑块是如何启用的,这里Android开发网告诉大家,辅助滚动滑块只需要一行代码就可以搞定,如果你使用XML布局只需要在ListView节点中加入 android:fastScrollEnabled="true" 这个属性即可,而对于Java代码可以通过myListView.setFastScrollEnabled(true); 来控制启用,参数false为隐藏。
还有一点就是当你的滚动内容较小,不到当前ListView的3个屏幕高度时则不会出现这个快速滚动滑块,同时该方法仍然是AbsListView的基础方法,可以在ListView或GridView等子类中使用快速滚动辅助。