- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
好的,我想我有一个真正的问题需要改变。我在 Android 中实现了一个 gridView,一步步遵循 Android 开发者页面中的说明,http://developer.android.com/resources/tutorials/views/hello-gridview.html我更改了它,以便在单击 View 时返回位图。这一切都适用于 Galxy Note 和 Galaxy S2 等高级手机,以及 Galaxy ace 等不太先进的手机,甚至是 2 年前的一些糟糕的 htc。但由于某种原因,由于 OutOfMemory 问题,它在带有 ICS 的 galaxy 3 上崩溃。当在 gridview 上使用大约一半的图像时,它确实有效(尽管有点慢)。这对任何人都有意义吗?
这是我对 ImageAdapter 的实现:
public class ImageAdapter extends BaseAdapter {
private Context mContext;
private int mWidth;
private int mHeight;
public ImageAdapter(Context c, int width, int height) {
mContext = c;
mWidth = width;
mHeight = height;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return mThumbIds[position];
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(mWidth, mHeight));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.third_world , R.drawable.annoyinggirl,
R.drawable.asianfather, R.drawable.awkawespeng,
R.drawable.awkpeng, R.drawable.blankdad,
R.drawable.collegesenior, R.drawable.courage,
R.drawable.frog, R.drawable.frynotsure,
R.drawable.goodguygreg, R.drawable.scumbag,
R.drawable.raptor,R.drawable.keano,
R.drawable.successkid, R.drawable.wonka,
R.drawable.braceyourselves, R.drawable.onedoesnotsimply,
R.drawable.firstworldproblem, R.drawable.amitheonlyone,
R.drawable.badluckbrian, R.drawable.interestingman,
R.drawable.toodamnhigh, R.drawable.def
};
这是我的主调用函数:
private void changeToTemplateView(){
setContentView(R.layout.templates);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(context, (int)(dstWidth * 1.4), (int)(dstHeight * 1.4)));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Options opts = new Options();
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), (int) parent.getItemIdAtPosition(position), opts);
//do stuff with bitmap
}
});
}
这是 gridview 的 xml:
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
如果有人知道我在这里可能做错了什么,我将永远感激
编辑:崩溃前,我在日志中收到一条错误消息:“FimgApiStretch:stretch failed”。此外,gridview 中的滚动不起作用。这与即使没有足够的缩略图导致滚动,应用程序仍然会崩溃这一事实无关
最佳答案
尝试将 fill_parent 替换为 match_parent 因为根据我的信息,属性值 fill_parent 在 android 2.2 及更高版本上已弃用希望这会有所帮助
你可以看到这个链接http://developer.android.com/training/displaying-bitmaps/load-bitmap.html希望对你有帮助
关于android gridview 在 Galaxy 3 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10999204/
我想在 galaxy fold 设备上查看我的页面时更改它的字体大小。但我不确定如何使用媒体查询来处理这个问题。任何人都可以帮助我并告诉我如何解决这个问题吗? 最佳答案 如果您需要对折叠版设备进行媒体
我想在 galaxy fold 设备上查看我的页面时更改它的字体大小。但我不确定如何使用媒体查询来处理这个问题。任何人都可以帮助我并告诉我如何解决这个问题吗? 最佳答案 如果您需要对折叠版设备进行媒体
我正在开发 Android Widget,需要区分 Galaxy S 和 Galaxy S2。我几乎阅读了所有关于屏幕尺寸和密度的文章。当然,我需要将新限定词与新限定词 Smallest Width
如何为 galaxy S3(720x1280 像素)和 galaxy Note(800x1280 像素)进行布局。 两者都是超高密度设备,因此我需要将两种设备的两组图像放在同一个文件夹 drawabl
我正在使用以下设置来初始化 MediaRecorder .我的应用程序在除三星以外的大多数设备上都能正常运行,并且在 MediaRecorder.stop() 上出现错误. recorder
我在连接到我的服务器以检查我的电话应用程序的凭据时遇到问题,我正在使用 phonegap 来开发它。 我已经检查过这些问题,但它们没有给我我正在寻找的东西 HTTP Requests in Phone
我想知道为什么 Galaxy S3 和 S4 从这个文件夹 (drawable-sw360dp-xhdpi) 获取图像?? 所有图像对于这些设备来说都显得非常大!另外,如果我将这些图像缩小,它们将不适
根据我的发现,Samsung galaxy s2 的分辨率为 480x800,而 s3 的分辨率为 1280x720。所以我认为我应该让我的图形设计师为我提供包含 480x800 背景图像的 hdpi
我有一部搭载 Android 4.0.2 和 NXP 演示板 PN532-C106 的 Galaxy Nexus 手机。 我正在尝试连接它们以使用 LLCP 协议(protocol)发送数据,我正在使
我在区分 samsung galaxy s4 和 samsung galaxy s3 的布局文件夹时遇到问题。我尝试过 layout-sw360dp、layout-sw360dp-xxhdpi、lay
我已经实现了一个 android 应用程序来在网络摄像头之间切换。我使用此代码 Android ICS and MJPEG using AsyncTask .它工作得很好。但是现在的问题。在对 Sam
我有一个奇怪的问题。我正在检索推特,它可以在模拟器和我的 Samsung Galaxy S 上运行,但它不能在我的 Galaxy Tab 10.1 上运行? 手机和标签页上都安装了相同的应用程序。从
我正在使用 FLASH_MODE_ON 打开相机 LED 灯。 三星 Galaxy Ace 只有三种闪光模式:开、关和自动。 FLASH_MODE_TORCH在三星 Galaxy Tab 和三星 Ga
我在安装以超时结束的 ansible 集合时遇到问题 # ansible-galaxy collection install community.general -vvvv ansible-galax
我正在尝试部署一个通过运行meteor部署appname创建的新应用程序,但它给了我这个错误...我使用我的meteor开发者用户名和密码登录... 我必须注册 Galaxy,还是无需注册就可以免费完
我正在尝试安装 Ansible Galaxy 集合,但我需要强制执行旧版本。 According to the documentation ,我尝试通过以下方式执行安装: $ ansible-gala
我正在尝试安装 Ansible Galaxy 集合,但我需要强制执行旧版本。 According to the documentation ,我尝试通过以下方式执行安装: $ ansible-gala
我的 friend 用他的新 galaxy 选项卡试用了我的应用程序,它似乎与我测试它的模拟器略有不同。他的应用程序选项菜单是黑色的,而不是白色背景,你无法真正看到任何选项,而且大多数应用程序都无法正
我是Andoid新手我想为 Galaxy 选项卡设计布局以及其他布局。我设计了四种布局Layout-small、large、xlarge 和 normal 布局。但是当我试图在 Galaxy 选项卡中
我想要做的就是有一个特定于桌面的版本,然后是一个可以在 iPhone、Android、iPad 和任何其他手持设备上运行的移动版本。 我现在检测桌面的是: @media only screen and
我是一名优秀的程序员,十分优秀!