- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我启动 Gallery Fragment 时,我遇到了强制关闭。这不是 Gallery 中的代码自 Ranghunandan向我展示了那里出了什么问题。我认为(但我不确定)它在 ImageAdapter 内。我还将发布 LogCat
这是 Java 代码
import java.lang.ref.WeakReference;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.support.v4.util.LruCache;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
public class ImageAdapter extends BaseAdapter {
private static final String TAG = "ImageAdapter";
private Context mContext;
public static final Integer[] TATTOOS = {
R.drawable.tattoo1, R.drawable.tattoo2,
R.drawable.tattoo3, R.drawable.tattoo4,
R.drawable.tattoo5, R.drawable.tattoo6,
R.drawable.tattoo7, R.drawable.tattoo8,
R.drawable.tattoo9, R.drawable.tattoo10,
/* R.drawable.tattoo11, R.drawable.tattoo12,
R.drawable.tattoo13, R.drawable.tattoo14,
R.drawable.tattoo15, R.drawable.tattoo16,
R.drawable.tattoo17, R.drawable.tattoo18,
R.drawable.tattoo19, R.drawable.tattoo20,
R.drawable.tattoo21, R.drawable.tattoo22,
R.drawable.tattoo23, R.drawable.tattoo24,
R.drawable.tattoo25, R.drawable.tattoo26,
R.drawable.tattoo27, R.drawable.tattoo28,
R.drawable.tattoo29, R.drawable.tattoo30,
R.drawable.tattoo31, R.drawable.tattoo32,
R.drawable.tattoo33, R.drawable.tattoo34,
R.drawable.tattoo35, R.drawable.tattoo36,
R.drawable.tattoo37, R.drawable.tattoo38,
R.drawable.tattoo39, R.drawable.tattoo40,
R.drawable.tattoo41, R.drawable.tattoo42,
R.drawable.tattoo43, R.drawable.tattoo44,
R.drawable.tattoo45, R.drawable.tattoo46,
R.drawable.tattoo47, R.drawable.tattoo48,
R.drawable.tattoo49, R.drawable.tattoo50,
R.drawable.tattoo51, R.drawable.tattoo52,
R.drawable.tattoo53, R.drawable.tattoo54,
R.drawable.tattoo55, R.drawable.tattoo56,
R.drawable.tattoo57, R.drawable.tattoo58,
R.drawable.tattoo59, R.drawable.tattoo60,
R.drawable.tattoo61, R.drawable.tattoo62,
R.drawable.tattoo63, R.drawable.tattoo64,
R.drawable.tattoo65, R.drawable.tattoo66,
R.drawable.tattoo67, R.drawable.tattoo68,
R.drawable.tattoo69, R.drawable.tattoo70,
R.drawable.tattoo71, R.drawable.tattoo72,
R.drawable.tattoo73, R.drawable.tattoo74,
R.drawable.tattoo75, R.drawable.tattoo76,
R.drawable.tattoo77, R.drawable.tattoo78,
R.drawable.tattoo79, R.drawable.tattoo80,
R.drawable.tattoo81, R.drawable.tattoo82*/
};
private Bitmap mHolder = null;
private static final int CACHE_SIZE = 30 * 1024 * 1024; // 8 MiB cache
/** Cache to store all decoded images */
private LruCache<Integer, Bitmap> mBitmapsCache = new LruCache<Integer, Bitmap>(CACHE_SIZE) {
@Override
protected int sizeOf(final Integer key, final Bitmap value) {
return value.getByteCount();
}
@Override
protected void entryRemoved(final boolean evicted, final Integer key, final Bitmap oldValue, final Bitmap newValue) {
if (!oldValue.equals(mHolder)) {
oldValue.recycle();
}
}
};
// Constructor
public ImageAdapter(Context c){
mContext = c;
mHolder = BitmapFactory.decodeResource(c.getResources(), R.drawable.ic_launcher, null);
}
@Override
public int getCount() {
return TATTOOS.length;
}
@Override
public Object getItem(int position) {
return TATTOOS[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//This actually is a bad solution, because every time convertView is reused, you will still initialize new ImageView, which is wrong
//ImageView imageView = new ImageView(this.mContext);
//new BitmapWorkerTask(imageView).execute(Tattoos[position]);
//return imageView;
//Better solution
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(this.mContext);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(280, 280));
} else {
imageView = (ImageView) convertView;
//re-use ImageView that already exists in memory
}
final Bitmap itemBitmap = mBitmapsCache.get(TATTOOS[position]);
if (itemBitmap == null || itemBitmap.isRecycled()) {
Log.e(TAG, position + " is missed, launch decode for " + TATTOOS[position]);
imageView.setImageBitmap(mHolder);
mBitmapsCache.put(TATTOOS[position], mHolder);
new BitmapWorkerTask(mBitmapsCache, mContext.getResources(), this).execute(TATTOOS[position]);
} else {
Log.e(TAG, position + " is here for " + TATTOOS[position]);
imageView.setImageBitmap(itemBitmap);
}
return imageView;
}
/** AsyncTask for decoding images from resources */
static class BitmapWorkerTask extends AsyncTask<Integer, Void, Bitmap> {
private int data = 0;
private final LruCache<Integer, Bitmap> mCache;
private final Resources mRes;
private final BaseAdapter mAdapter;
public BitmapWorkerTask(LruCache<Integer, Bitmap> cache, Resources res, BaseAdapter adapter) {
// nothing to do here
mCache = cache;
mRes = res;
mAdapter = adapter;
}
// Decode image in background.
@Override
protected Bitmap doInBackground(Integer... params) {
data = params[0];
return decodeSampledBitmapFromResource(mRes, data, 300, 300);
}
// Once complete, see if ImageView is still around and set bitmap.
@Override
protected void onPostExecute(Bitmap bitmap) {
mCache.put(data, bitmap);
mAdapter.notifyDataSetChanged();
}
}
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
options.outHeight = 300;
options.outWidth = 300;
return BitmapFactory.decodeResource(res, resId, options);
}
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
// Calculate ratios of height and width to requested height and width
final int heightRatio = Math.round((float) height / (float) reqHeight);
final int widthRatio = Math.round((float) width / (float) reqWidth);
// Choose the smallest ratio as inSampleSize value, this will guarantee
// a final image with both dimensions larger than or equal to the
// requested height and width.
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
}
return inSampleSize;
}
}
这是 LogCat
12-25 13:55:13.722: D/AndroidRuntime(7065): Shutting down VM
12-25 13:55:13.722: W/dalvikvm(7065): threadid=1: thread exiting with uncaught exception (group=0x419c5b90)
12-25 13:55:13.752: D/dalvikvm(7065): GC_FOR_ALLOC freed 179K, 3% free 9923K/10136K, paused 20ms, total 20ms
12-25 13:55:13.752: E/AndroidRuntime(7065): FATAL EXCEPTION: main
12-25 13:55:13.752: E/AndroidRuntime(7065): Process: info.androidhive.slidingmenu, PID: 7065
12-25 13:55:13.752: E/AndroidRuntime(7065): android.util.SuperNotCalledException: Fragment GalleryActivity{4238f5d8 #0 id=0x7f0a0008} did not call through to super.onActivityCreated()
12-25 13:55:13.752: E/AndroidRuntime(7065): at android.app.Fragment.performActivityCreated(Fragment.java:1710)
12-25 13:55:13.752: E/AndroidRuntime(7065): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:908)
12-25 13:55:13.752: E/AndroidRuntime(7065): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
12-25 13:55:13.752: E/AndroidRuntime(7065): at android.app.BackStackRecord.run(BackStackRecord.java:684)
12-25 13:55:13.752: E/AndroidRuntime(7065): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
12-25 13:55:13.752: E/AndroidRuntime(7065): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:443)
12-25 13:55:13.752: E/AndroidRuntime(7065): at android.os.Handler.handleCallback(Handler.java:733)
12-25 13:55:13.752: E/AndroidRuntime(7065): at android.os.Handler.dispatchMessage(Handler.java:95)
12-25 13:55:13.752: E/AndroidRuntime(7065): at android.os.Looper.loop(Looper.java:137)
12-25 13:55:13.752: E/AndroidRuntime(7065): at android.app.ActivityThread.main(ActivityThread.java:4998)
12-25 13:55:13.752: E/AndroidRuntime(7065): at java.lang.reflect.Method.invokeNative(Native Method)
12-25 13:55:13.752: E/AndroidRuntime(7065): at java.lang.reflect.Method.invoke(Method.java:515)
12-25 13:55:13.752: E/AndroidRuntime(7065): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
12-25 13:55:13.752: E/AndroidRuntime(7065): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
12-25 13:55:13.752: E/AndroidRuntime(7065): at dalvik.system.NativeStart.main(Native Method)
12-25 14:00:13.902: I/Process(7065): Sending signal. PID: 7065 SIG: 9
最佳答案
logcat 告诉您,您没有调用 super onActivityCreated();
错误不在您的适配器中。在堆栈跟踪中查看这一行:
android.util.SuperNotCalledException:Fragment GalleryActivity{4238f5d8 #0 id=0x7f0a0008} 未调用 super.onActivityCreated()
onActivityCreated 方法需要此调用,并且应如下所示:
@Override
onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// do something here
}
关于java - 使用 Fragment 强制关闭图库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20775968/
这是一个链接:http://lomakincello.net/etu/sehen.php 我正在使用 HTML 和 CSS 创建一个网站。我不熟悉 JavaScript,所以有人帮助我制作了一个运行
大家好。我的目标是为自己的新爱好摄影创建一个个人作品集网站。 目前一切就绪。 (这个可以看here。) 问题是,尽我所能,我无法在 CSS 中替换图像。我花了很长时间试图移动图像等,但它只是悲惨地失败
我对画廊有疑问。我无法通过触摸滚动。通过 DPAD 或轨迹球滚动效果很好。 这是一些代码:xml布局: 适配器: package de.goddchen.android.advent.tem
是否有一个社区站点包含一组自定义控件或他们如何调用它为 View ,人们可以在其中获取和重用或发布比标准 UI 组件集更高级的东西? 最佳答案 OpenIntents.org has a bunch
我看了很多论坛,也试过很多东西,就是无法添加PS图库我在公司代理后面,但我已经设置了我的个人资料来使用它。我正在尝试使用这些命令注册 PS 存储库 [Net.ServicePointManager]:
我目前正在尝试在现有的 C++ 项目中使用 boost 图形库。我想将自定义类的对象存储在 boost 图中。下面是一个小示例,其中包含具有两个成员(一个字符串和一个整数)的自定义类定义及其相应的 g
需要从路径获取图像。我已经尝试了所有方法,但似乎没有得到图像。 我的两个图片路径: /storage/emulated/0/DCIM/Camera/20161025_081413.jpg conten
我正在使用 Turbolinks 开发 Android 和 iOS 网络应用程序。 我正在尝试使用 native View /进程实现拍摄新照片或从图库中选择一张照片。 我的表单中有这一行 当我通过
我正在尝试实现诸如适用于 Android 的 Airbnb 应用程序的效果,列出每行中水平滚动画廊的位置(并且每行都有带标题的顶层)。我在每个单元格中使用带有 FrameLayout 和 ViewPa
好吧,我是编码初学者。我下载了 Galereya Jquery 脚本。它有效,但它与代码中它下面的所有其他内容重叠。我尝试更改溢出和位置,但似乎没有任何效果。当我将它添加到另一个 div 中时,网格停
这是我在 stackoverflow 上的第一篇文章。因此,对于这篇文章中的一些不典型内容,我深表歉意。 我编写了一个带有画廊 slider 的 Django 网站,但我不知道为什么图像太大。看这里:
我正在处理一个网站的图库,它由显示所有图片的缩略图 block 组成以及用于显示特定图像的部分。 这是我用来以实际大小显示缩略图和图像的代码。 问题是:我想不出任何东西来设置打开图像的大小。设
我使用 jquery 制作了一个简单的画廊,但是左右按钮不起作用?? 我使用了 jquery 函数 first().appendTo 和 last().prependTo 请检查下面的链接 Mydem
好的伙计们,请不要杀了我,这是我的第一个问题,我对编程知之甚少:)所以我想用灯箱画廊创建一个简单的网站,你可以看看它here . 所以我无法解决的问题是,当您向下滚动页面时,照片后面没有黑色背景。 我
我正在编写自己的图形库 Graph++ ,我对接口(interface)应该返回什么有疑问。例如,我的 BFS 应该返回什么,我很困惑它是否应该返回按顺序访问的一组 vertices ,或者我应该有
我一直在使用图库控件来显示照片,但在滑动照片时遇到问题。我需要一直滑动才能更改照片,否则它会弹回到上一张照片。 在互联网上查询后,我听说画廊已被弃用。下一个可以与画廊控件执行相同操作的控件是什么? 最
为了上大学,我必须在 android 上开发一个带有面部检测的应用程序。为此,我必须在我的画廊中保存各种照片。问题是保存照片后,图库不会更新。更准确地说,如果我删除了我要保存图像的目录,我打开应用程序
我正在这样使用图库 但是当我运行代码时,我发现画廊从中间开始,我想从左边开始。我该怎么办,请帮助我。 最佳答案 描述有关显示的一般信息的结构,例如其大小、密度和字体缩放。要访问 DisplayMe
我试图让用户从他的设备中选择图像或视频,目前它只显示视频或图像,具体取决于以下代码中首先写入的内容: Intent galleryIntent = new Intent(Intent.ACTION_
我正在创建一个 cover flow通过扩展 Gallery 类来处理图像。 画廊 View 显示正常,但图像从右向左滚动的速度非常快,反之亦然。 有什么方法可以调节图像在水平方向上从右到左移动的速度
我是一名优秀的程序员,十分优秀!