当前位置: 编程技术>移动开发
本页文章导读:
▪采取ViewHolder模式提高AdapterView显示的效率 采用ViewHolder模式提高AdapterView显示的效率
如果对效率要求比较高的话可以采用这种办法,唯一的缺点就是多了一个内部类ViewHolder。public View getView(int pos, View convertView, ViewGroup parent){
.........
▪ Gallery默许第一项居左解决方案 Gallery默认第一项居左
网上找的,暂时用不到没测试过。Android 中的Gallery控件默认会将第一项居中显示,在某些场景会影响用户体验,分享一下居左的:/**
* Align the first gallery item to the left..........
▪ 第八节(Activity格局初步一) 第八节(Activity布局初步一)
一、LinearLayout
<?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"
.........
[1]采取ViewHolder模式提高AdapterView显示的效率
来源: 互联网 发布时间: 2014-02-18
采用ViewHolder模式提高AdapterView显示的效率
如果对效率要求比较高的话可以采用这种办法,唯一的缺点就是多了一个内部类ViewHolder。
getView(int pos, View convertView, ViewGroup parent)里的pos嘛
如果对效率要求比较高的话可以采用这种办法,唯一的缺点就是多了一个内部类ViewHolder。
public View getView(int pos, View convertView, ViewGroup parent){
ViewHolder holder;
if (convertView == null) {
holder=new ViewHolder();
convertView = mInflater.inflate(R.layout.list_item, null);
holder.text = (TextView) convertView.findViewById( R.id.text));
holder.icon = (ImageView) convertView.findViewButId( R.id.icon));
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(DATA[pos]);
holder.icon.setImageBitmap((pos & 1) == 1 ? mIcon1 : mIcon2);
return convertView;
}
static class ViewHolder {
TextView text;
ImageView icon;
}
1 楼
lizhanzhishang
2012-05-03
holder.icon.setImageBitmap((pos & 1) == 1 ? mIcon1 : mIcon2);
这里的pos是怎么得到的?(pos & 1)这点不懂,请指教
这里的pos是怎么得到的?(pos & 1)这点不懂,请指教
2 楼
lizhanzhishang
2012-05-03
还有个问题:为什么会有好多的数据来填充整个View?这是系统默认的,还是什么原因?可以修改为,自己想要的数据量嘛?谢谢
3 楼
gundumw100
2012-05-03
lizhanzhishang 写道
holder.icon.setImageBitmap((pos & 1) == 1 ? mIcon1 : mIcon2);
这里的pos是怎么得到的?(pos & 1)这点不懂,请指教
这里的pos是怎么得到的?(pos & 1)这点不懂,请指教
getView(int pos, View convertView, ViewGroup parent)里的pos嘛
[2] Gallery默许第一项居左解决方案
来源: 互联网 发布时间: 2014-02-18
Gallery默认第一项居左
网上找的,暂时用不到没测试过。
Android 中的Gallery控件默认会将第一项居中显示,在某些场景会影响用户体验,分享一下居左的:
http://androidit.diandian.com/post/b8c29a20-e368-11e0-94a3-782bcb32ff27
Android自定义Gallery,实现CoverFlow效果
http://bigcat.easymorse.com/?p=1391
网上找的,暂时用不到没测试过。
Android 中的Gallery控件默认会将第一项居中显示,在某些场景会影响用户体验,分享一下居左的:
/**
* Align the first gallery item to the left.
*
* @param parentView The view containing the gallery widget (we assume the gallery width
* is set to match_parent)
* @param gallery The gallery we have to change
*/
private void alignGalleryToLeft(View parentView, Gallery gallery) {
int galleryWidth = parentView.getWidth();
// We are taking the item widths and spacing from a dimension resource because:
// 1. No way to get spacing at runtime (no accessor in the Gallery class)
// 2. There might not yet be any item view created when we are calling this
// function
int itemWidth = context.getResources()
.getDimensionPixelSize(R.dimen.gallery_item_width);
int spacing = context.getResources()
.getDimensionPixelSize(R.dimen.gallery_spacing);
// The offset is how much we will pull the gallery to the left in order to simulate
// left alignment of the first item
int offset;
if (galleryWidth <= itemWidth) {
offset = galleryWidth / 2 - itemWidth / 2 - spacing;
} else {
offset = galleryWidth - itemWidth - 2 * spacing;
}
offset = 0;
// Now update the layout parameters of the gallery in order to set the left margin
MarginLayoutParams mlp = (MarginLayoutParams) gallery.getLayoutParams();
mlp.setMargins(-offset, mlp.topMargin, mlp.rightMargin, mlp.bottomMargin);
}http://androidit.diandian.com/post/b8c29a20-e368-11e0-94a3-782bcb32ff27
Android自定义Gallery,实现CoverFlow效果
http://bigcat.easymorse.com/?p=1391
[3] 第八节(Activity格局初步一)
来源: 互联网 发布时间: 2014-02-18
第八节(Activity布局初步一)
一、LinearLayout
<?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:orientation="vertical"- -指定控件排列方向
android:layout_width="fill_parent"
android:layout_height="fill_parent"
-->
<!--
android:id="@+id/btn_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="第2行"
android:gravity="center"- -指定控件的基本位置比如居中、居右等位置
android:textSize="20pt"- -指定控件当中文本字体大小
android:background="#aa0000"- -指定控件背景色,使用RGB命名法
android:padding....- -指定控件内容的边距
android:layout_weight="2"- -指定控件在布局中占用屏幕的比例
android:singleLine="true"- -指定控件是的内容是否在同一行中展示
-->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:layout_weight="5"
/>
<Button
android:id="@+id/btn_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="第2行第2行第2行第2行第2行第2行第2行第2行第2行第2行第2行第2行第2行第2行"
android:gravity="top"
android:textSize="20pt"
android:background="#aa0000"
android:paddingLeft="10dip"
android:paddingTop="1dip"
android:paddingRight="30dip"
android:paddingBottom="40dip"
android:layout_weight="1"
android:singleLine="true"
/>
</LinearLayout>
二、TableLayout
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0"
>
<!-- android:stretchColumns="0"如果不能撑满窗口,拉伸第0列填满窗口 -->
<TableRow>
<TextView
android:text="column1"
android:padding="5dip"
android:background="#aa0000"
/>
<TextView
android:text="column2"
android:padding="5dip"
android:background="#0000aa"
android:layout_gravity="center_vertical"
/>
<TextView
android:text="column3"
android:padding="5dip"
android:background="#00aa00"
/>
</TableRow>
<TableRow>
<TextView
android:text="column1"
android:padding="5dip"
/>
<TextView
android:text="column2"
android:padding="5dip"
/>
<TextView
android:text="column3"
android:padding="5dip"
/>
</TableRow>
</TableLayout>
最新技术文章: