0

While scrolling the gallery last item is scrolled and stops at left margin. I want to stop the last item at right margin of the screen. i am showing 3 items at a time on screen thanks for any suggestions.

   public View getView(int position, View convertView, ViewGroup parent) { 
  Gallery newArticleRow;
  LinearLayout layout = (LinearLayout) convertView;
  if (layout == null) {
    Log.d("in home", "HomeActivityListViewAdapter--- new getView:" + position);

    // Inflate the news article row
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    convertView = inflater.inflate(R.layout.news_articles_row, null);

    newArticleRow = (Gallery) convertView
        .findViewById(R.id.news_articles_gallery);

    DisplayMetrics metrics = new DisplayMetrics();

    FishwrapHomeActivity.this.getWindowManager().getDefaultDisplay()
        .getMetrics(metrics);
    MarginLayoutParams mlp = (MarginLayoutParams) newArticleRow
        .getLayoutParams();
    mlp.setMargins(-(metrics.widthPixels - (int) TypedValue.applyDimension(
        TypedValue.COMPLEX_UNIT_DIP, 90, FishwrapHomeActivity.this
            .getResources().getDisplayMetrics())), mlp.topMargin,
        mlp.rightMargin, mlp.bottomMargin);
    newArticleRow.setId(position);
    newArticleRow.setLayoutParams(mlp);
    convertView.setTag(newArticleRow);
    convertView.setBackgroundColor(Color.WHITE);
    convertView.setFocusableInTouchMode(false);
  } else {
    Log.d("in home", "HomeActivityListViewAdapter--- old getView:" + position);
    // Get the newArticleRow HorizontialListView
    newArticleRow = (Gallery) convertView.getTag();
  }

  // Set the adapter only if the ArticleRow
  if (newArticleRow.getAdapter() == null || newArticleRow.getAdapter() != rowAdapters.get(position)) {
    newArticleRow.setAdapter(rowAdapters.get(position));
    newArticleRow.setOnItemClickListener(itemListener);
  }

 // Debug.stopMethodTracing();

  return convertView;
}
raju
  • 1,254
  • 13
  • 18
  • please give more information and what you have done – Dipak Keshariya Jun 07 '12 at 05:40
  • Hi i posted getview method code please have a look. i just want while scrolling the gallery, scrolling should stop at right side if it is the last item in gallary – raju Jun 07 '12 at 09:35
  • @Rekha i have one sollution but i think which not as much good as in my sollution first start item with middle and after that it will start from left and last item remain at right and if u again reverse gallary than first item also go on right side this thing happen if need this sollution than tell me i will give u code for that – Khan Jun 28 '12 at 05:17
  • @khan please give me the code i will try. – raju Jul 09 '12 at 05:43

1 Answers1

0

@Rekha i think you should stop further scrolling functionality in that direction when position = lastitem - 1 element. You might want to do that through your Gallery instance ( gallery.getSelectedItemPosition() ) and the onscrollistener.

by the way, does this solve your previous "position restarts gallery in listview" issue? i have a similar issue that repeats my gallerys within my list when using a gallery holder.

  • i solved the duplicates in the listview. solution is very simple just use the listview hieght as fill parent instead of wrapcontent. – raju Jul 09 '12 at 05:41