android 组件更新内容之后的刷新小结
来源:互联网 发布:淘宝手表带价格及图片 编辑:程序博客网 时间:2024/06/07 22:09
在android开发过程中,当我们对一个TextView更新内容之后,并且会改变界面布局的高度的时候。比如:
1.布局文件
<?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" >
<RelativeLayout
android:id="@+id/author_lay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/tab_item_bg"
android:paddingBottom="5dip"
>
<TextView
android:id="@+id/author_name_tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="5dip"
android:singleLine="true"
android:textColor="@color/item_name"
android:textSize="16dip" />
<TextView
android:id="@+id/author_des_tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/author_name_tv"
android:layout_margin="5dip"
android:textColor="@color/black"
android:textSize="16dip" />
</RelativeLayout>
<ImageView
android:id="@+id/author_line"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/line" />
<ListView
android:id="@+id/author_works_lv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="@color/transparent"
android:divider="@drawable/line"
android:fadeScrollbars="true"
android:fadingEdge="none"
android:scrollbarThumbVertical="@drawable/scroll" />
</LinearLayout>
2. 关键代码
TextView authorDesTV;
authorDesTV = (TextView) findViewById(R.id.author_des_tv);
authorDesTV.setText(getString(R.string.author_description, authorDes));
//设置Tag,根据Tag的值来判断authorDesTV是否展开
authorDesTV.setTag(false);
authorDesTV.setMaxLines(4);
1)通过view的requestLayout()方法来刷新界面
authorDesTV.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
boolean isExpend = (Boolean) authorDesTV.getTag();
if (isExpend) {
authorDesTV.setTag(false);
authorDesTV.setMaxLines(4);
authorDesTV.requestLayout();
} else {
authorDesTV.setTag(true);
authorDesTV.setMaxLines(20);
authorDesTV.setEllipsize(null);
}
}
});
2)通过view的invalidate()方法来刷新界面
authorDesTV.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
boolean isExpend = (Boolean) authorDesTV.getTag();
if (isExpend) {
authorDesTV.setTag(false);
authorDesTV.setMaxLines(4);
authorDesTV.invalidate();
} else {
authorDesTV.setTag(true);
authorDesTV.setMaxLines(20);
authorDesTV.setEllipsize(null);
}
}
});
3)通过ListView的scrollBy()方法来刷新界面
authorDesTV.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
boolean isExpend = (Boolean) authorDesTV.getTag();
if (isExpend) {
authorDesTV.setTag(false);
authorDesTV.setMaxLines(4);
authorWorksLV.scrollBy(0, 1);
} else {
authorDesTV.setTag(true);
authorDesTV.setMaxLines(20);
authorDesTV.setEllipsize(null);
}
}
});
3.第一种方式是通过重新布局来请求界面刷新;
第二种方式是view的刷新方法;
第三种方式是间接通过重新布局的方式来请求界面刷新。
4.最后如果通过以上三种方式均不能够实现界面刷新,那就要考虑尝试以下方式:
1)对RelativeLayout添加一个android:clipChildren属性;
<RelativeLayout
android:id="@+id/author_lay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/tab_item_bg_hover"
android:paddingBottom="5dip"
android:clipChildren="true"
>
2)对listview添加一个背景android:background="@drawable/window_bg"。
<ListView
android:id="@+id/author_works_lv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/window_bg"
android:cacheColorHint="@color/transparent"
android:divider="@drawable/line"
android:fadeScrollbars="true"
android:fadingEdge="none"
android:scrollbarThumbVertical="@drawable/scroll" />
- android 组件更新内容之后的刷新小结
- Jquery Mobile中组件内容更新后的刷新办法
- C#无刷新的更新界面内容
- Android刷新组件的学习
- ExtJs保存之后刷新本页面 (小结)
- jquery无刷新更新内容
- php保存submit内容之后禁止刷新
- 要不断刷新页面才能看见更新的内容
- 用刷新网页的办法更新user control控件内容
- Android打造通用的下拉刷新组件
- Android打造通用的下拉刷新组件
- Android打造通用的下拉刷新组件
- Android官方刷新组件 SwipeRefreshLayout 的使用
- Android SwipeRefreshLayout 下拉刷新组件的使用
- SwipeRefreshLayout(Android的下拉刷新组件)
- Android下拉刷新组件
- android四大组件小结
- android 组件 - Service小结
- opencv 直方图均衡化
- Smack:Packet属性
- 【javascript】动态改变样式
- Dom4j quick start guide
- WebApp前端常用属性总结
- android 组件更新内容之后的刷新小结
- oracle执行效率
- MICA2
- C语言指针
- Linux sed命令用法
- 删除 Windows Azure 网站上的标准服务器头
- word2007用法--如何不出现转换文件
- GPG key retrieval failed: [Errno 14] Could not open/read file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
- java 访问修饰符