// 1xx: Informational - Request received, continuing process
100 => 'Continue',
101 => 'Switching Protocols',
// 2xx: Success - The action was successfully received, understood and
// accepted
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
// 3xx: Redirection - Further action must be taken in order to complete
// the request
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found', // 1.1
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
307 => 'Temporary Redirect',
// 4xx: Client Error - The request contains bad syntax or cannot be
// fulfilled
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',
// 5xx: Server Error - The server failed to fulfill an apparently
// valid request
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
509 => 'Bandwidth Limit Exceeded',
package cn.hwttnet.com.ui; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import cn.hwttnet.com.adapter.GridAdapter; import cn.hwttnet.com.bean.GridInfo; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.DialogInterface.OnClickListener; import android.os.Bundle; import android.view.View; import android.view.Window; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.GridView; public class MainActivity extends Activity { private GridView gridview; private GridAdapter adapter; Context context = MainActivity.this; Class<?> mActivities[] = { RegistrationActivity.class, AnnouncementActivity.class, WorkflowActivity.class ,WorkLogActivity.class, }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); } void init() { gridview = (GridView) findViewById(R.id.gridview); adapter = new GridAdapter(getList(), context); gridview.setAdapter(adapter); gridview.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub onListItemClick(arg2); } }); } void onListItemClick(int index) { if (index < 0 || index >= mActivities.length) return; Intent intent = new Intent(context, mActivities[index]); this.startActivity(intent); } protected void onStart() { super.onStart(); init(); } protected void onResume() { super.onResume(); } ArrayList<GridInfo> getList() { ArrayList<GridInfo> list = new ArrayList<GridInfo>(); GridInfo gif1 = new GridInfo(); gif1.setImages(R.drawable.ic_launcher); gif1.setName("上班签到"); GridInfo gif2 = new GridInfo(); gif2.setImages(R.drawable.ic_launcher); gif2.setName("通知公告"); GridInfo gif3 = new GridInfo(); gif3.setImages(R.drawable.ic_launcher); gif3.setName("工作流"); GridInfo gif4 = new GridInfo(); gif4.setImages(R.drawable.ic_launcher); gif4.setName("工作日志"); list.add(gif1); list.add(gif2); list.add(gif3); list.add(gif4); return list; } }
package cn.hwttnet.com.adapter; import java.util.ArrayList; import java.util.List; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.TextView; import cn.hwttnet.com.bean.GridInfo; import cn.hwttnet.com.ui.R; public class GridAdapter extends BaseAdapter { ArrayList<GridInfo> list; Context context; public GridAdapter(ArrayList<GridInfo> list,Context context) { this.list=list; this.context=context; } public int getCount() { // TODO Auto-generated method stub return list.size(); } public Object getItem(int position) { // TODO Auto-generated method stub return list.get(position); } public long getItemId(int position) { // TODO Auto-generated method stub return position; } public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub if(convertView==null) { LayoutInflater layout=LayoutInflater.from(context); convertView=layout.inflate(R.layout.grid_item, null); } ImageView itemImg=(ImageView)convertView.findViewById(R.id.itemImage); TextView itemName=(TextView)convertView.findViewById(R.id.itemText); itemImg.setImageResource(list.get(position).getImages()); itemName.setText(list.get(position).getName()); return convertView; } }
package cn.hwttnet.com.bean; public class GridInfo { String name; int images; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getImages() { return images; } public void setImages(int images) { this.images = images; } }
android:layout_centerHrizontal 水平居中
android:layout_centerVertical 垂直居中
android:layout_centerInparent 相对于父元素完全居中
android:layout_alignParentBottom 贴紧父元素的下边缘
android:layout_alignParentLeft 贴紧父元素的左边缘
android:layout_alignParentRight 贴紧父元素的右边缘
android:layout_alignParentTop 贴紧父元素的上边缘
android:layout_alignWithParentIfMissing 如果对应的兄弟元素找不到的话就以父元素做参照物
android:layout_below 在某元素的下方
android:layout_above 在某元素的的上方
android:layout_toLeftOf 在某元素的左边
android:layout_toRightOf 在某元素的右边
android:layout_alignLeft 本元素的左边缘和某元素的的左边缘对齐
android:layout_alignBottom 本元素的下边缘和某元素的的下边缘对齐
android:layout_alignRight 本元素的右边缘和某元素的的右边缘对齐
android:layout_marginBottom 离某元素底边缘的距离
android:layout_marginLeft 离某元素左边缘的距离
android:layout_marginRight 离某元素右边缘的距离
android:layout_marginTop 离某元素上边缘的距离
这里要特别注意dip与屏幕密度有关,而屏幕密度又与具体的硬件有关,硬件设置不正确,有可能导致dip不能正常显示。在屏幕密度为160的显示屏上,1dip=1px,有时候可能你的屏幕分辨率很大如480*800,但是屏幕密度没有正确设置比如说还是160,那么这个时候凡是使用dip的都会显示异常,基本都是显示过小。
dip的换算:
dip(value)=(int) (px(value)/1.5 + 0.5)
2. dp: 很简单,和dip是一样的。
3. px: pixels(像素),不同的设备不同的显示屏显示效果是相同的,这是绝对像素,是多少就永远是多少不会改变。
4. sp: scaled pixels(放大像素). 主要用于字体显示best for textsize。
public static int dip2px(Context context, float dipValue){
final float scale = context.getResources().getDisplayMetrics().density;
return (int)(dipValue * scale + 0.5f);
}
public static int px2dip(Context context, float pxValue){
final float scale = context.getResources().getDisplayMetrics().density;
return (int)(pxValue / scale + 0.5f);
}