<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">本筆記主要是記錄平時開發時遇到的細節方面的問題或者常用的小功能的記錄。</span>
1.動態設置佈局中ImageView的圖片
public void initTitleBar() {
ibTab1Left.setBackgroundResource(R.drawable.money_set);
ibTab1Right.setBackgroundResource(R.drawable.money_share);
tvTitle.setText(R.string.tab1_driving_account_details);
// ibTab1Left.getResources().getDrawable(R.drawable.money_set);
// ibTab1Right.getResources().getDrawable(R.drawable.money_share);
// ibTab1Left.setImageDrawable(getResources().getDrawable(R.drawable.money_set));
// ibTab1Right.setImageDrawable(getResources().getDrawable(R.drawable.money_share));
}
2.利用List動態設置TextView文本信息
此處用了Annotations註解框架
@ViewsById({ R.id.text1, R.id.text2 })
List<TextView> list;
@AfterViews
public void setTextView() {
for (TextView textele : list) {
list.get(0).setText("hello");
list.get(1).setText("world");
}
}
3.Eclipse/Android Studio 快捷鍵
Ctrl+Shift+X→小寫轉大寫
Ctrl+Shift+Y→大寫轉小寫
4.BaseAdapter使用步驟
1.創建一個MyAdapter繼承BaseAdapter
2.實現BaseAdapter裏面的方法
3.創建構造方法,eg.(Context context,List<String> list)
4.修改getCount()返回值爲list.size
5.修改getItem()方法返回值爲list.get(position)
6.修改getItemId返回值爲position
7重寫getView()方法
5.double,int轉化爲String類型
String.valueOf(int)
String.valueOf(double)
6.調用系統相機注意點
1.啓動方式
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
2.註冊Camera功能(其他應用請求系統相機時會彈出選擇對話框),寫在AndroidManifest.xml中
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
7.頁面跳轉動畫效果
從左到右滑出
push_left_in:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="100%p" android:toXDelta="0"
android:duration="200" />
</set>
push_left_out:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="-100%p"
android:duration="200" />
</set>
從右到左滑出
push_right_in:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="100%p"
android:duration="200" />
</set>
push_right_out:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="-100%p" android:toXDelta="0"
android:duration="200" />
</set>
8.在Fragment裏面設定點擊事件
事件不要在onCreateView裏面加,需要的話再onActivityCreate裏邊加,使用方法和在activity裏邊是一樣的。
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
initEvents();
}
9.在Fragment中用BaseAdapter裏面getView()方法怎麼用
@Override
public View getView(int position, View arg1, ViewGroup parent) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_layout, parent, false);
<span style="white-space:pre"> </span>//getLayoutInflater().inflate(R.layout.item_layout, null);
ImageView touxiang = (ImageView) view.findViewById(R.id.iv_touxiang);
TextView neirong = (TextView) view.findViewById(R.id.tv_neirong);
touxiang.setImageResource(imageids[position]);
neirong.setText(descStrings[position]);
return view;
}
10.Android TextView文字加下劃線
tvForgetPassword.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);