Polish for the gallery sample demo.
Change-Id: I3ea34ac090554494bf09e71aaa08a9148a0ab42a
This commit is contained in:
@@ -14,8 +14,19 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<Gallery xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gallery"
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_height="wrap_content"
|
android:id="@+id/layout2"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent">
|
||||||
|
<Gallery android:id="@+id/gallery"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
/>
|
/>
|
||||||
|
<EditText
|
||||||
|
android:text="@+id/EditText01"
|
||||||
|
android:id="@+id/EditText01"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"></EditText>
|
||||||
|
</LinearLayout>
|
||||||
@@ -71,7 +71,24 @@ public class Gallery1 extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class ImageAdapter extends BaseAdapter {
|
public class ImageAdapter extends BaseAdapter {
|
||||||
int mGalleryItemBackground;
|
private static final int ITEM_WIDTH = 136;
|
||||||
|
private static final int ITEM_HEIGHT = 88;
|
||||||
|
|
||||||
|
private final int mGalleryItemBackground;
|
||||||
|
private final Context mContext;
|
||||||
|
|
||||||
|
private final Integer[] mImageIds = {
|
||||||
|
R.drawable.gallery_photo_1,
|
||||||
|
R.drawable.gallery_photo_2,
|
||||||
|
R.drawable.gallery_photo_3,
|
||||||
|
R.drawable.gallery_photo_4,
|
||||||
|
R.drawable.gallery_photo_5,
|
||||||
|
R.drawable.gallery_photo_6,
|
||||||
|
R.drawable.gallery_photo_7,
|
||||||
|
R.drawable.gallery_photo_8
|
||||||
|
};
|
||||||
|
|
||||||
|
private final float mDensity;
|
||||||
|
|
||||||
public ImageAdapter(Context c) {
|
public ImageAdapter(Context c) {
|
||||||
mContext = c;
|
mContext = c;
|
||||||
@@ -81,6 +98,8 @@ public class Gallery1 extends Activity {
|
|||||||
mGalleryItemBackground = a.getResourceId(
|
mGalleryItemBackground = a.getResourceId(
|
||||||
R.styleable.Gallery1_android_galleryItemBackground, 0);
|
R.styleable.Gallery1_android_galleryItemBackground, 0);
|
||||||
a.recycle();
|
a.recycle();
|
||||||
|
|
||||||
|
mDensity = c.getResources().getDisplayMetrics().density;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
@@ -96,30 +115,25 @@ public class Gallery1 extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
ImageView i = new ImageView(mContext);
|
ImageView imageView;
|
||||||
|
if (convertView == null) {
|
||||||
|
convertView = new ImageView(mContext);
|
||||||
|
|
||||||
i.setImageResource(mImageIds[position]);
|
imageView = (ImageView) convertView;
|
||||||
i.setScaleType(ImageView.ScaleType.FIT_XY);
|
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
|
||||||
i.setLayoutParams(new Gallery.LayoutParams(136, 88));
|
imageView.setLayoutParams(new Gallery.LayoutParams(
|
||||||
|
(int) (ITEM_WIDTH * mDensity + 0.5f),
|
||||||
|
(int) (ITEM_HEIGHT * mDensity + 0.5f)));
|
||||||
|
|
||||||
// The preferred Gallery item background
|
// The preferred Gallery item background
|
||||||
i.setBackgroundResource(mGalleryItemBackground);
|
imageView.setBackgroundResource(mGalleryItemBackground);
|
||||||
|
} else {
|
||||||
return i;
|
imageView = (ImageView) convertView;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Context mContext;
|
imageView.setImageResource(mImageIds[position]);
|
||||||
|
|
||||||
private Integer[] mImageIds = {
|
return imageView;
|
||||||
R.drawable.gallery_photo_1,
|
}
|
||||||
R.drawable.gallery_photo_2,
|
|
||||||
R.drawable.gallery_photo_3,
|
|
||||||
R.drawable.gallery_photo_4,
|
|
||||||
R.drawable.gallery_photo_5,
|
|
||||||
R.drawable.gallery_photo_6,
|
|
||||||
R.drawable.gallery_photo_7,
|
|
||||||
R.drawable.gallery_photo_8
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user