Wednesday, April 9, 2014

Gallery problem, seeking advice


With gallery and browse pictures switcher wrote a program, to run properly, but slipped back after the termination of the picture to be wrong
This is my source, the great God who help look
  
android: orientation = "vertical"
android: layout_width = "fill_parent"
android: layout_height = "fill_parent"
>


android: layout_width = "fill_parent" android: layout_height = "fill_parent"
android: layout_alignParentTop = "true" android: layout_centerHorizontal = "true"
/>
android: layout_width = "fill_parent"
android: layout_height = "60px"
android: layout_alignParentLeft = "true"
android: layout_alignParentBottom = "true"
android: background = "# 55000000"
android: gravity = "center_vertical"
android: spacing = "16dp"
/>

 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.ViewGroup.LayoutParams;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ImageView;
import android.widget.ViewSwitcher.ViewFactory;

public class GalleryActivity extends Activity implements OnItemSelectedListener,
ViewFactory {
/ ** Called when the activity is first created. * /
/ / Private Gallery gallery;
private ImageSwitcher mSwitcher;

private int [] mimage_s = new int []
{R.drawable.image_s_1, R.drawable.image_s_2, R.drawable.image_s_3, R.drawable.image_s_4,
R.drawable.image_s_5, R.drawable.image_s_6, R.drawable.image_s_7};
private int [] mimages = new int []
{R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4,
R.drawable.image5, R.drawable.image6, R.drawable.image7};
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
requestWindowFeature (Window.FEATURE_NO_TITLE);
setContentView (R.layout.main);
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);
}

@ Override
public View makeView () {
/ / TODO Auto-generated method stub
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;
}

@ Override
public void onItemSelected (AdapterView adapter, View v, int position,
long id) {
/ / TODO Auto-generated method stub
mSwitcher.setImageResource (mimages [position]);
}

@ Override
public void onNothingSelected (AdapterView arg0) {
/ / TODO Auto-generated method stub

}
public class ImageAdapter extends BaseAdapter {
public ImageAdapter (Context c)
{
mContext = c;
}

@ Override
public int getCount () {
/ / TODO Auto-generated method stub
return mimage_s.length;
}

@ Override
public Object getItem (int position) {
/ / TODO Auto-generated method stub
return position;
}

@ Override
public long getItemId (int position) {
/ / TODO Auto-generated method stub
return position;
}

@ Override
public View getView (int position, View convertView, ViewGroup parent) {
/ / TODO Auto-generated method stub
ImageView i = new ImageView (mContext);
i.setImageResource (mimage_s [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;
}

}
code
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
I tried it on the simulator, does not complain ah. You put the wrong log Tieshanglai.

Reply:
Estimate is a memory overflow
Reply:

This is
interface running out on the following gallery should be left feeling quite normal forNo problem before a few pictures to the back of a few points on the wrong
Reply:
reference to the second floor youngc527 reply:
is estimated that memory overflow

That how to get ah
Reply:
Not yet been solved, Dinga top
Reply:
Brother: Gallery are outdated, but also with ViewPager + FragmentStatePagerAdapter suggest you use it?!
Reply:
LogCat inside the log you want to go out stickers analysis.
Reply:
reference to the 7th floor tantahe reply:
LogCat you should go out stickers inside the log analysis.

How should I look? ? I was a novice
Reply:
There eclipse LogCat label, tap the DDMS of devices in your device or simulator, LogCat can see the log here
Reply:
Pictures and more memory overflow, Baidu "android image cache"
Reply:
reference to the 10th floor lieri111 reply:
pictures and more memory overflow, Baidu "android image cache"

Indeed a memory overflow say is Option but with a specific error code should be how to modify it
Reply:
http://www.oschina.net/code/snippet_219356_18887

No comments:

Post a Comment