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;
}
4

1 回答 1

0

@Rekha 我认为当 position = lastitem - 1 元素时,您应该停止在该方向上进一步滚动功能。您可能希望通过您的 Gallery 实例 ( gallery.getSelectedItemPosition() ) 和 onscrolllistener 来执行此操作。

顺便问一下,这是否解决了您之前的“位置重新启动列表视图中的画廊”问题?当使用画廊持有人时,我有一个类似的问题,在我的列表中重复我的画廊。

于 2012-06-29T08:25:00.630 回答