Adapter listview 。
,adapter getview() , 。 , 。 。
xml :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal">
<ImageView android:id="@+id/icon"
android:layout_width="48dip"
android:layout_height="48dip" />
<TextView android:id="@+id/text"
android:layout_gravity="center_vertical"
android:layout_width="0dip"
android:layout_weight="1.0"
android:layout_height="wrap_content" />
</LinearLayout>
1。 ,
public View getView(int pos, View convertView,
ViewGroup parent){
View item = mInflater.inflate(R.layout.list_item, null);
((TextView) item.findViewById(R.id.text)).
setText(DATA[pos]);
((ImageView) item.findViewButId(R.id.icon)).
setImageBitmap((pos & 1) == 1 ? mIcon1 : mIcon2);
return item;
}
2。 convertview , 200%。
public View getView(int pos, View convertView,
ViewGroup parent){
if (convertView == null) {
convertView = mInflater.inflate(
R.layout.list_item, null);
}
((TextView) convertView.findViewById(R.id.text)).
setText(DATA[pos]);
((ImageView) convertView.findViewButId(R.id.icon)).
setImageBitmap((pos & 1) == 1 ? mIcon1 : mIcon2);
return convertView;
}
3。 viewholder , 50%
static class ViewHolder {
TextView text;
ImageView icon;
}
public View getView(int pos, View convertView, ViewGroup parent){
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_item, null);
holder = new ViewHolder();
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;
}
adapter :
1 10 frames/second
2 30 frames/second
3 40 frames/second
1。
2。
3。
originalImage = Bitmap.createScaledBitmap(
originalImage, //
view.getWidth(), //
view.getHeight(), //
true); //
1 25 frames/second
2 50 frames/second
,
-
-
layout_width = fill_parent
layout_height = fill_parent
:
1。
public void onCreate(Bundle icicle){
super.onCreate(icicle);
setContentView(R.layout.mainview);
//
getWindow().setBackgroundDrawable(null);
...
}
2。 xml
res/values/styles.xml
<resources>
<style name="NoBackgroundTheme" parent="android:Theme">
<item name="android:windowBackground">@null</item>
</style>
</resources>
androidmainfest.xml
<activity android:name="MyApplication"
android:theme="@style/NoBackgroundTheme">
...
</activity>
, invalidate() , , , 。
,
invalidate(Rect dirty);
invalidate(int left, int top, int right, int
bottom);
, , ,
:
1。 textview drawable
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello"
android:drawableLeft="@drawable/icon"/>
2。 viewstuf
xml viewstuf
<ViewStub android:id = "@+id/stub_import"
android:inflatedId="@+id/panel_import"
android:layout="@layout/progress_overlay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"/>
,
findViewById(R.id.stub_import).setVisibility(View.VISIBLE);
//
View importPanel = ((ViewStub)
findViewById(R.id.stub_import)).inflate();
3。 <merge>
, , , merge
<merge xmlns:android =
"http://schemas.android.com/apk/res/android">
<! -- Content -->
</merge>
4。 ralativelayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageView android:id="@+id/icon"
android:layout_width="48dip" android:layout_height="48dip"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/text_line1"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/icon"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/text_line2"
android:layout_toRightOf="@id/icon"
android:layout_below="@id/text_line1"/>
<Checkbox android:id="@+id/star"
android:layout_width="48dip" android:layout_height="48dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
5.
class CustomView extends View {
@Override
protected void onDraw(Canvas canvas) {
//
}
@Override
protected void onMeasure(int widthMeasureSpec,
int heightMeasureSpec) {
//
setMeasuredDimension(widthSpecSize, heightSpecSize);
}
}
6
class GridLayout extends ViewGroup {
@Override
protected void onLayout(boolean changed, int l, int t,
int r, int b) {
final int count = getChildCount();
for (int i=0; i < count; i++) {
final View child = getChildAt(i);
if (child.getVisibility() != GONE) {
//
child.layout(left, top, right, bottom);
}
}
}
}
, java
1。 onmeasure()
2。 onlayout()
3。 ondraw() dispatchdraw()
4。 ontouchevent() dispatchtouchevent()
5。adapter: getview() bindview()
( )
int prevLimit = -1;
try {
prevLimit = Debug.setAllocationLimit(0);
//
} catch (dalvik.system.AllocationLimitError e) {
// , Java
Log.e(LOGTAG, e);
} finally {
Debug.setAllocationLimit(prevLimit);
}
:
1。 :
2。 :
:
private final HashMap<String, SoftReference<T>> mCache;
public void put(String key, T value) {
mCache.put(key, new SoftReference<T>(value));
}
public T get(String key, ValueBuilder builder) {
T value = null;
SoftReferece<T> reference = mCache.get(key);
if (reference != null) {
value = reference.get();