=============急 安卓 gallery 滑动图片,图片左右跳动怎么解决======
安卓使用gallery显示图片,在滑动图片时,有时(90%)图片会左右跳动,哆嗦。。。不显示下一个图片。这种情况怎么解决?这个已经解决了好几个星期了。。。
xml文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.suma.activity.smartplayer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/suma_shape_image_bg"
android:orientation="vertical" >
<Gallery
android:id="@+id/home_gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:spacing="0dip" />
....
</RelativeLayout>
这个是gallery中的item 对应的getview
public View getView(int position, View convertView, ViewGroup parent) {
ImageView image = null;
if (convertView == null) {
image = new ImageView(mContext);
} else {
image = (ImageView) convertView;
}
//使用ImageLoader加载图片
imageLoader.displayImage(resourceList.get(position).getPicUrl(), image, options);
WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
int screenWidth = wm.getDefaultDisplay().getWidth();
image.setLayoutParams(new Gallery.LayoutParams(screenWidth, screenWidth * 211 / 516));
return image;
}
[解决办法]
到不了第二张,这不清楚啊,还没遇到过这样的情况,多贴点代码看看,怎么设置的,你要是不太依赖Gallery的话,我建议用viewpage,个人建议。
[解决办法]
左右跳动大概是图片界面自动调整了吧?移动过去了,又调整到正常位置,不显示下一个图片这个明显就是你没加载到下一个图片
[解决办法]
你的position是不是没有改变过?给份东西你参考下吧。感觉你改一下就可以完成上面的问题了
package com.eoemobile.book.ex_widgetdemo;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ViewSwitcher;
import android.widget.Gallery.LayoutParams;
public class ImageShowActivity extends Activity implements
AdapterView.OnItemSelectedListener, ViewSwitcher.ViewFactory {
CheckBox plain_cb;
CheckBox serif_cb;
CheckBox italic_cb;
CheckBox bold_cb;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.image_show);
setTitle("ImageShowActivity");
mSwitcher = (ImageSwitcher) findViewById(R.id.switcher);
mSwitcher.setFactory(this);
mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_in));
mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_out));
Gallery g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this));
g.setOnItemSelectedListener(this);
}
public void onItemSelected(AdapterView parent, View v, int position, long id) {
mSwitcher.setImageResource(mImageIds[position]);
}
public void onNothingSelected(AdapterView parent) {
}
public View makeView() {
ImageView i = new ImageView(this);
i.setBackgroundColor(0xFF000000);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
return i;
}
private ImageSwitcher mSwitcher;
public class ImageAdapter extends BaseAdapter {
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);
i.setImageResource(mThumbIds[position]);
i.setAdjustViewBounds(true);
i.setLayoutParams(new Gallery.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
i.setBackgroundResource(R.drawable.picture_frame);
return i;
}
private Context mContext;
}
private Integer[] mThumbIds = {
R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
R.drawable.sample_thumb_6, R.drawable.sample_thumb_7};
private Integer[] mImageIds = {
R.drawable.sample_0, R.drawable.sample_1, R.drawable.sample_2,
R.drawable.sample_3, R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7};
}
XML:
<ImageSwitcher
android:id="@+id/switcher"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" />
<Gallery android:id="@+id/gallery"
android:background="#55000000"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:gravity="center_vertical"
android:spacing="16dp" />
[解决办法]
希望能帮助到你
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- 定义一个ImageSwitcher组件 -->
<ImageSwitcher android:id="@+id/switcher"
android:layout_width="320dp"
android:layout_height="320dp"
/>
<!-- 定义一个Gallery组件 -->
<Gallery android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:unselectedAlpha="0.6"
android:spacing="3pt"
/>
</LinearLayout>