項目:拉手團購
10.27
構建框架
下載數據
注意字段名要一致
使用Gson解析JsonArray時,代碼如下:
Gson gson = new Gson(); Type type = new TypeToken<ArrayList<數據類型>>(){}.getType(); ArrayList<數據類型>list = gson.fromjson(json,type);
其中Type爲Java.lang.reflect.type
TypeToken爲Gson.reflect.typeToken
設置GridView的間距
豎直方向的item的間隔用android:verticalSpacing="15dp"
如何設置圖片大小
根據屏幕大小的幾分之幾來設置
10.29
ListView中刷新命令只與ListView的getView有關,與HeadView都沒有關係
自定義GridView以適應在ListView嵌套中能夠滑動,適用於數量不多的情況,因爲優化全部失效
解決不同分辨率顯示效果不同,通過屏幕尺寸來設置佈局的大小,代碼:
// 得到屏幕參數 WindowManager systemService = (WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE); mDisplay = systemService.getDefaultDisplay();
Gson解析
使用工具jsonschema2pojo快速創見Gson解析需要的類
刪除無用的@…,由於工具的原因,下劃線_下劃線都被替換成了-,改之
11.05
標籤欄的切換動畫
ObjectAnimator.ofFloat(mTabIndiactor, "translationX", 0).setDuration(500).start();
注意,這裏只設置了到哪裏去而沒有從哪裏開始
點擊進入商品詳情(ScrollView的使用)
將各式各樣的佈局以及多個listview添加ScrollView中
自定義ListView使其能夠在ScrollView中正常顯示
通過webView顯示超文本
mBendanWeb.loadDataWithBaseURL(null, mData.getDetails(),"text/html", "UTF-8", null);
給文本添加劃掉效果
textview.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
代碼控制ScrollView的滾動
scrollview.scrollTo(0,0); scrollview.smoothScrollTo(0,0);
indeterminateOnly屬性
android:indeterminateOnly這個屬性如果設置爲true,表示的是這個ProgressBar是模糊的,不明確的,也就是說,當前它並沒有體現出具體的進度,只是一直循環往復
11.11
自定義RatingBar
關鍵屬性:
progressDrawable
,MaxHeight
,MinHeight
添加點擊撥號功能
直接開啓系統的撥號功能,在代碼中傳入需要撥打的號碼
Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+"110"));
跳轉到撥號界面
Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW); intent.setType("vnd.android.cursor.item/sim-contact");
控件懸停功能
添加支付懸浮
思路:
當scrollView上下滑動時,支付佈局2有條件的Gone或者Visible。
Gone:默認
Visible:此時scrollView滑動的高度>=圖片控件的高度
時時監聽scrollView滑動距離
自定義ScrollView,並聲明一個設置監聽的方法
MyScrollView代碼:
package com.jensen.quiet; import android.content.Context; import android.util.AttributeSet; import android.widget.ScrollView; public class MyScrollView extends ScrollView { private OnScrollListener listener; public interface OnScrollListener { void onScroll(int height); } public void setOnScrollListener(OnScrollListener listener) { this.listener = listener; } public MyScrollView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { listener.onScroll(t); super.onScrollChanged(l, t, oldl, oldt); } }
點擊查看詳情圖片
ViewPager + 圖片加載UIL + 黑色背景
城市列表以及城市定位
ListView
字母索引(開源項目)
將所有數據按照字母排序
側邊字母索引
11.16
在xml中設置無ActionBar模式
在values文件下得styles文件中添加如下代碼:
<style name="NoBar" parent="android:Theme.Light.NoTitleBar"></style>
在values-v14文件夾下的styles中添加如下代碼:
<style name="NoBar" parent="android:Theme.Holo.Light.NoActionBar"></style>
在清單文件的application標籤下添加:
android:theme="@style/NoBar"
dp,sp,px的關係
dp(dip): device independent pixels(設備獨立像素). 不同設備有不同的顯示效果,這個和設備硬件有關,一般我們爲了支持WVGA、HVGA和QVGA 推薦使用這個,不依賴像素。
dp也就是dip,這個和sp基本類似。如果設置表示長度、高度等屬性時可以使用dp 或sp。但如果設置字體,需要使用sp。dp是與密度無關,sp除了與密度無關外,還與scale無關。如果屏幕密度爲160,這時dp和sp和px是一 樣的。1dp=1sp=1px,但如果使用px作單位,如果屏幕大小不變(假設還是3.2寸),而屏幕密度變成了320。那麼原來TextView的寬度 設成160px,在密度爲320的3.2寸屏幕裏看要比在密度爲160的3.2寸屏幕上看短了一半。但如果設置成160dp或160sp的話。系統會自動 將width屬性值設置成320px的。也就是160 * 320 / 160。其中320 / 160可稱爲密度比例因子。也就是說,如果使用dp和sp,系統會根據屏幕密度的變化自動進行轉換。
px: pixels(像素). 不同設備顯示效果相同,一般我們HVGA代表320x480像素,這個用的比較多。
pt: point,是一個標準的長度單位,1pt=1/72英寸,用於印刷業,非常簡單易用;
sp: scaled pixels(放大像素). 主要用於字體顯示best for textsize。
在GridView中顯示網格的一種方法
該網格線是通過設置GridView各子項的間隔,並分別設置GridView背景色與子項背景色實現的。
實現方法
設置GridView背景色,設置水平間方向間隔屬性值
android:horizontalSpacing
和豎直方向間隔屬性值android:verticalSpacing
設置GridView子項背景色,要求 子項背景色跟GridView背景色不一致。
代碼中設置TextView中的圖片的方法
Drawable drawable= getResources().getDrawable(R.drawable.drawable); // 這一步必須要做,否則不會顯示. drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); myTextview.setCompoundDrawables(drawable,null,null,null);
或
myTextview.setCompoundDrawablesWithIntrinsicBounds (Drawable left,Drawable top, Drawable right, Drawable bottom)
完善界面細節
耗時工程,以下省略一千字
自定義CheckBox的背景
使用xml屬性:button
使用Bmob開放接口
添加手機驗證碼登錄
ButterKnife的使用
查看GitHub上的源碼,知道了怎麼使用CheckBox的監聽
@OnCheckedChanged(R.id.simple_activity_checkbox) void onCheckedChanged(CompoundButton button, boolean checked) { Toast.makeText(this, "CheckBox Changed! " + checked, Toast.LENGTH_SHORT).show(); }
給EditText添加監聽
addTextChangedListener(TextWatcher watcher)
方法對EditText實現監
完成全部分類界面
完成我的拉手界面繪製
11.20
給自定義控件添加xml屬性
如何使用自定義控件的屬性
在自定義控件中使用自定義屬性:
app:contentSize=“10dp”
在佈局中聲明新的命名空間:xmlns即xml name space。拷貝android命名控件,前面的Android改爲app(可變),後面/android改爲-auto。
xmlns:app="http://schemas.android.com/apk/res-auto"
拷貝ApiDemos中的attires.xml文件,保留LabelView屬性,刪除其他,並按需求修改命名。
在類文件中的兩個參數的構造方法中讀取控件的屬性,代碼如下
參考ApiDemosresvaluesattrs.xml。步驟:
public MySideBar(Context context, AttributeSet attrs) { super(context, attrs); // 添加屬性 //R.styleable.MySideBar就是剛剛在attrs.xml中定義的屬性 TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attrs, R.styleable.MySideBar); // 讀具體的某個屬性 dimen = obtainStyledAttributes.getDimension(R.styleable.MySideBar_contentSize, 20); //釋放內存 obtainStyledAttributes.recycle(); }
ActiveAndroid保存一對多的數據類型
在location界面中添加城市搜索功能
思路:在location中添加一個ListView用於顯示搜索結果,定義一個容器儲存搜索匹配拼音的結果,爲EditText添加輸入監聽
修改佈局,使用FrameLayout
關鍵代碼:
mSerach.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // 漢字的話要使用拼音庫 String key = s.toString().toLowerCase(); mSerachCity.clear(); serachAdapter.notifyDataSetChanged(); if ("".equals(key)) { mSearchListView.setVisibility(View.GONE); } else { mSearchListView.setVisibility(View.VISIBLE); for (int i = 0; i < mAllcity.size(); i++) { Allcity city = mAllcity.get(i); if (city.getPinyin().toLowerCase().startsWith(key)) { mSerachCity.add(city); serachAdapter.notifyDataSetChanged(); } } } }
11.21
自定義頭像
升級ADT和SDK
ActionBarSherlock庫發生奇葩錯誤,ERROR: In <declare-styleable> SherlockSpinner, unable to find attribute android:popupPromptView。解決:API版本不能大於19,於是我選擇用4.4.2來作爲編譯的主力軍
11.22
分享到新浪微博
新浪微博授權成功時會得到一個Token
11.24
完成登錄功能
完成定位界面的點擊事件
顯示密碼
mInputPwd.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);//可見 mInputPwdConfirm.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);//隱藏
11.25
收藏界面
點擊隨便逛逛跳轉到周邊界面,使用了
mTabHost.setCurrentTab(index);
方法。
自定義RadioButton
關鍵屬性button,可以設成想要的按鈕樣式,設成@null的時候就看不到選框了