android.widget.GridView.getChildAt()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(178)

本文整理了Java中android.widget.GridView.getChildAt()方法的一些代码示例,展示了GridView.getChildAt()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GridView.getChildAt()方法的具体详情如下:
包路径:android.widget.GridView
类名称:GridView
方法名:getChildAt

GridView.getChildAt介绍

暂无

代码示例

代码示例来源:origin: TonicArtos/StickyGridHeaders

View child = super.getChildAt(i);
if (firstVisibleItem == 0 && super.getChildAt(0).getTop() > 0
    && !mClippingToPadding) {
  mHeaderBottomPosition = 0;

代码示例来源:origin: huburt-Hu/NewbieGuide

@Override
  public void run() {
    //高亮gridView的第2个子view
    View childAt = gridView.getChildAt(1);
    NewbieGuide.with(GridViewActivity.this)
        .setLabel("grid_view_guide")
        .alwaysShow(true)
        .addGuidePage(GuidePage.newInstance()
            .addHighLight(childAt, HighLight.Shape.RECTANGLE)
            .setEverywhereCancelable(false)
            .setLayoutRes(R.layout.view_guide, R.id.iv))
        .show();
  }
});

代码示例来源:origin: stackoverflow.com

GridView myGridView = (GridView) findViewById(R.id.gridview);
ViewGroup griditem = (ViewGroup) myGridView.getChildAt(0); //First item
for(int i = 0; i < griditem.getChildCount(); ++i) {
  if(griditem.getChildAt(i) instaceof TextView)
    griditem.getChildAt(i).requestFocus();
}

代码示例来源:origin: stackoverflow.com

final GridView imageContainer = // your GridView
imageContainer.getViewTreeObserver().addOnGlobalLayoutListener( new OnGlobalLayoutListener() 
      {
      @Override
      public void onGlobalLayout() 
        {
        imageContainer.getViewTreeObserver().removeGlobalOnLayoutListener( this );
        View lastChild = imageContainer.getChildAt( imageContainer.getChildCount() - 1 );
        imageContainer.setLayoutParams( new LinearLayout.LayoutParams( LayoutParams.FILL_PARENT, lastChild.getBottom() ) );
        }
      });

代码示例来源:origin: UweTrottmann/SeriesGuide

View child = super.getChildAt(i);
if (firstVisibleItem == 0 && super.getChildAt(0).getTop() > 0
    && !mClippingToPadding) {
  mHeaderBottomPosition = 0;

代码示例来源:origin: stackoverflow.com

private void checkGridView(GridView gridView) {
  for (int i = 0; i < gridView.getChildCount() ; i++ ){
    View v = gridView.getChildAt(i);
    CheckBox checkBox = (CheckBox) v.findViewById(R.id.custom_adapter_add_checkbox);
    boolean itemChecked = checkBox.isChecked();
  }
}

代码示例来源:origin: stackoverflow.com

public View getViewByPosition(int pos, GridView gridView) {
  final int firstListItemPosition = listView.getFirstVisiblePosition();
  final int lastListItemPosition = firstListItemPosition + listView.getChildCount() - 1;

  if (pos < firstListItemPosition || pos > lastListItemPosition ) {
    return gridView.getAdapter().getView(pos, null, listView);
  } else {
    final int childIndex = pos - firstListItemPosition;
    return gridView.getChildAt(childIndex);
  }
}

代码示例来源:origin: stackoverflow.com

@Override
protected void onPause() {
  GridView gridView = (GridView) findViewById(R.id.public_photos);
  int count = gridView.getCount();
  for (int i = 0; i < count; i++) {
    ImageView v = (ImageView) gridView.getChildAt(i);
    if (v != null) {
      if (v.getDrawable() != null) v.getDrawable().setCallback(null);
    }
  }
  super.onPause();
}

代码示例来源:origin: stackoverflow.com

GridView calendarView = (GridView)findViewById(R.id.YOUR_VIEW_ID);
ViewTreeObserver viewTreeObserver = calendarView.getViewTreeObserver(); 
viewTreeObserver.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 
  @Override 
  public void onGlobalLayout() { 
    this.calendarView.getViewTreeObserver().removeGlobalOnLayoutListener(this); 
    View v = calendarView.getChildAt(position);

    if (v!=null) {
      v.setSelected(true);
    }
  }
});

代码示例来源:origin: stackoverflow.com

GridView gridView = (GridView) findViewById(R.id.gridview);
View selected =gridView.getChildAt(position);
CheckedTextView selectedCheck = (CheckedTextView)selected.findViewById(R.id.imageTick);
selectedCheck.setChecked(true);
selectedCheck.setVisibility(View.VISIBLE);

代码示例来源:origin: googlecodelabs/android-topeka

private void setUpUserInput() {
  mAnswerView.performItemClick(mAnswerView.getChildAt(mAnswered), mAnswered,
      mAnswerView.getAdapter().getItemId(mAnswered));
  mAnswerView.getChildAt(mAnswered).setSelected(true);
  mAnswerView.setSelection(mAnswered);
}

代码示例来源:origin: OceanLabs/Android-Print-SDK

/*****************************************************
 *
 * Returns a bitmap version of the specified item from
 * the GridView (first item has position 0)
 * Returns blank image in case of failure
 *
 *****************************************************/
public static Bitmap getItemBitmap(GridView view, int position) {
  try {
    View item = view.getChildAt(position);
    item.setDrawingCacheEnabled(true);
    item.buildDrawingCache(true);
    Bitmap bitmap = Bitmap.createBitmap(item.getDrawingCache());
    item.setDrawingCacheEnabled(false);
    return bitmap;
  } catch (Exception e) {
    Log.e(LOG_TAG, "Unable to get item bitmap", e);
    return getBlankBitmap();
  }
}

代码示例来源:origin: stackoverflow.com

@ViewById(R.id.gridViewId)
GridView gridView;

@ItemClick(R.id.gridViewId)
void itemClicked(int position) {
  int firstPosition = gridView.getFirstVisiblePosition();
  int lastPosition = gridView.getLastVisiblePosition();

  View clickedView;

  if ((position < firstPosition) || (position > lastPosition))
    clickedView = null;

  clickedView = gridView.getChildAt(position - firstPosition);
  // do sg with clicked view
}

代码示例来源:origin: stackoverflow.com

private View getViewByPosition(GridView gridView, int position) {
  int firstPosition = gridView.getFirstVisiblePosition();
  int lastPosition = gridView.getLastVisiblePosition();

  if ((position < firstPosition) || (position > lastPosition))
    return null;

  return gridView.getChildAt(position - firstPosition);
}

代码示例来源:origin: chengzichen/KrGallery

private PhotoPickerPhotoCell getCellForIndex(int index) {
  int count = listView.getChildCount();
  for (int a = 0; a < count; a++) {
    View view = listView.getChildAt(a);
    if (view instanceof PhotoPickerPhotoCell) {
      PhotoPickerPhotoCell cell = (PhotoPickerPhotoCell) view;
      int num = (Integer) cell.photoImage.getTag();
      if (selectedAlbum != null) {
        if (num < 0 || num >= selectedAlbum.photos.size()) {
          continue;
        }
      } else {
        ArrayList<MediaController.SearchImage> array;
        if (searchResult.isEmpty() && lastSearchString == null) {
          array = recentImages;
        } else {
          array = searchResult;
        }
        if (num < 0 || num >= array.size()) {
          continue;
        }
      }
      if (num == index) {
        return cell;
      }
    }
  }
  return null;
}

代码示例来源:origin: fire3/sailorcast

@Override
  public void onScroll(AbsListView view, int firstVisibleItem,
             int visibleItemCount, int totalItemCount) {
    boolean enable = false;
    if (mGrid != null && mGrid.getChildCount() > 0) {
      // check if the first item of the list is visible
      boolean firstItemVisible = mGrid.getFirstVisiblePosition() == 0;
      // check if the top of the first item is visible
      boolean topOfFirstItemVisible = mGrid.getChildAt(0).getTop() == 0;
      // enabling or disabling the refresh layout
      enable = firstItemVisible && topOfFirstItemVisible;
    }
    mSwipeContainer.setEnabled(enable);
  }
});

代码示例来源:origin: fire3/sailorcast

@Override
  public void onScroll(AbsListView view, int firstVisibleItem,
             int visibleItemCount, int totalItemCount) {
    boolean enable = false;
    if (mGrid != null && mGrid.getChildCount() > 0) {
      // check if the first item of the list is visible
      boolean firstItemVisible = mGrid.getFirstVisiblePosition() == 0;
      // check if the top of the first item is visible
      boolean topOfFirstItemVisible = mGrid.getChildAt(0).getTop() == 0;
      // enabling or disabling the refresh layout
      enable = firstItemVisible && topOfFirstItemVisible;
    }
    mSwipeContainer.setEnabled(enable);
  }
});

代码示例来源:origin: reloZid/android-anuto

private void updateArrowVisibility() {
    if (grid_maps.getChildCount() <= 0) {
      arrow_up.setVisibility(View.INVISIBLE);
      arrow_down.setVisibility(View.INVISIBLE);
      return;
    }

    if (grid_maps.getFirstVisiblePosition() == 0) {
      arrow_up.setVisibility(grid_maps.getChildAt(0).getTop() < -10 ? View.VISIBLE : View.INVISIBLE);
    } else {
      arrow_up.setVisibility(grid_maps.getFirstVisiblePosition() > 0 ? View.VISIBLE : View.INVISIBLE);
    }

    if (grid_maps.getLastVisiblePosition() == mAdapter.getCount() - 1) {
      arrow_down.setVisibility(grid_maps.getChildAt(grid_maps.getChildCount() - 1).getBottom() > grid_maps.getHeight() + 10 ? View.VISIBLE : View.INVISIBLE);
    } else {
      arrow_down.setVisibility(grid_maps.getLastVisiblePosition() < mAdapter.getCount() - 1 ? View.VISIBLE : View.INVISIBLE);
    }
  }
}

代码示例来源:origin: googlecreativelab/lipswap

@Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
    boolean checked) {
  //highlight stuff if it should be checked
  GridViewItem item = (GridViewItem) mGridView
      .getChildAt(position - mGridView.getFirstVisiblePosition());
  item.animateHighlight(checked);
  Log.d(TAG, "onItemCheckedStateChanged() " + position + " id: " + id + " checked: "
      + checked);
  if (checked) {
    mSelectedItems.add(item);
  } else {
    mSelectedItems.remove(item);
  }
  if (mSelectedItems.size() > 1) {
    //more than one selected, so disable sharing
    mode.getMenu().findItem(R.id.action_share).setEnabled(false);
  } else if (mSelectedItems.size() == 1) {
    mode.getMenu().findItem(R.id.action_share).setEnabled(true);
  }
}

代码示例来源:origin: stackoverflow.com

GridView.getViewTreeObserver.addOnGlobalLayoutListener(getLayoutListener(mGridView))
private static ViewTreeObserver.OnGlobalLayoutListener getLayoutListener(final GridView mGridView) {
  ViewTreeObserver.OnGlobalLayoutListener listener = new ViewTreeObserver.OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
      View view = mGridView.getChildAt(0);
      if(view != null) {
        if(!view.isSelected()) {
          view.setSelected(true);
        } else {
          // remove the listener after the first time.
          if (Build.VERSION.SDK_INT < 16) {
            mGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
          } else {
            mGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
          }
        }
      }
    }
  };

  return listener;
}

相关文章

GridView类方法