1、记录Android心得及点滴
2、android ListView详解
3、RGB颜色查询对照表
4、为了做到优化ListView或GridView,适配器写法,代码记录。
public class RecordListAdapter extends BaseAdapter { public Context context; public ArrayList<PlayRecordDate> list; LayoutInflater inflater; public RecordListAdapter(Context context, ArrayList<PlayRecordDate> list, FinalBitmap fb) { this.context = context; this.list = list; inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); } @Override public int getCount() { // TODO Auto-generated method stub return list.size(); } @Override public Object getItem(int position) { // TODO Auto-generated method stub return list.get(position); } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } public class ViewHolder { private ImageView playrecord_img; private TextView playrecord_name; } @Override public View getView(final int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub ViewHolder holder = null; if (convertView == null) { holder = new ViewHolder(); convertView = inflater.inflate( R.layout.gridview_playrecord_item_layout, null); holder.playrecord_img = (ImageView) convertView .findViewById(R.id.play_record_img); holder.playrecord_name = (TextView) convertView .findViewById(R.id.play_record_name); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.playrecord_img.setBackgroundResource(R.drawable.bgselector); holder.playrecord_name.setText(list.get(position).getVideoName()); return convertView; } }
5.使用GridView时,通用代码记录
<GridView android:id="@+id/grid" android:layout_width="fill_parent" android:layout_height="fill_parent" android:cacheColorHint="#00000000" android:listSelector="#00000000" android:verticalSpacing="35px" <!-- grid元素之间的竖直间隔 如果想改变列数,可以改变这个值来达到要求 --> android:horizontalSpacing="5px" <!--grid元素之间的水平间隔 --> android:numColumns="auto_fit" <!--表示有多少列,如果设置为auto_fit,将根据columnWidth和Spacing来自动计算 --> android:columnWidth="100px" <!-- 一般建议采用有像素密度无关的dip或者dp来表示--> android:stretchMode="SpacingWidth" <!--如何填满空余的位置,模拟器采用WVGA800*480,每排4列,有4*100+5*3=415, 还余65px的空间,如果是columnWidth,则这剩余的65将分摊给4列,每列增加16/17px。 如果采用SpacingWidth,则分摊给3个间隔空隙 --> android:gravity="center" />
常用GridView每项的布局
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="220dp" android:layout_height="wrap_content" > <ImageView android:id="@+id/play_record_img" android:layout_width="220dp" android:layout_height="300dp" android:layout_centerHorizontal="true" android:scaleType="fitXY"/> <TextView//当字数比较多的时候,该TextView会滚动显示文字 解决TextView不用获取焦点也能实现跑马灯 android:id="@+id/play_record_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/play_record_img" android:layout_centerHorizontal="true" android:ellipsize="marquee" android:lines="1" android:marqueeRepeatLimit="marquee_forever" android:singleLine="true" android:textColor="#FFFFFF" android:textSize="26dip" /> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_focused="true" android:drawable="@drawable/select"></item> <item android:state_selected="true" android:drawable="@drawable/select"></item> </selector>