I have an android application with a gallery that switches between textswitcher views. It always starts in between two textswitcher views. Why does this happen? I'm setting the selection to a specific position.
getWindow().setFlags(Windo开发者_JAVA技巧wManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); g = (Gallery) findViewById(R.id.gallery); g.setAnimationDuration(200); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
g.setAdapter(hello);
g.setSpacing(20);
g.setSelection(2);
Although this is an old question, I had the same problem and maybe it helps others. This was the crucial part of my Adapter:
public View getView(int position, View convertView, ViewGroup parent) {
Display display = ((WindowManager) c.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
LayoutInflater inflater = LayoutInflater.from(c);
View view = inflater.inflate(R.layout.date_list_item, parent,false);
view.setLayoutParams(new Gallery.LayoutParams(width/3, Gallery.LayoutParams.MATCH_PARENT));
I wanted to have three items shown at the same time, so I took parent.getWidth()/3
. however this led the gallery to start between two views. Getting the displays width shown in the upper code-sample worked fine for me
精彩评论