List of usage examples for android.view ViewGroup getChildAt
public View getChildAt(int index)
From source file:com.dahl.brendan.wordsearch.view.WordSearchActivity.java
/** * creates a grid of textViews from layout files based on the gridSize * and sets the new textViews to use the controller as their listener * /*from w w w.ja v a 2s . c o m*/ * @param gridSize square size of the new grid to make * @param controller the onkeyListener used for the grid's textViews, also holds the gridView an array of the new textView's in the grid */ public void setupViewGrid() { control.setLetter(null); int gridSize = control.getGridSize(); TextViewGridController controller = control.getGridManager(); ViewGroup gridTable = (ViewGroup) this.findViewById(R.id.gridTable); if (gridTable.getChildCount() != gridSize) { if (gridTable.getChildCount() == 0) { gridTable.setKeepScreenOn(true); gridTable.setOnTouchListener(controller); } controller.clearPointDemension(); gridTable.removeAllViews(); Point point = new Point(); controller.setGridView(new TextView[gridSize][]); TextView[][] gridView = controller.getGridView(); for (point.y = 0; point.y < gridSize; point.y++) { this.getLayoutInflater().inflate(R.layout.grid_row, gridTable, true); ViewGroup row = (ViewGroup) gridTable.getChildAt(point.y); TextView[] rowText = new TextView[gridSize]; for (point.x = 0; point.x < gridSize; point.x++) { this.getLayoutInflater().inflate(R.layout.grid_text_view, row, true); TextView view = (TextView) row.getChildAt(point.x); view.setId(ConversionUtil.convertPointToID(point, control.getGridSize())); view.setOnKeyListener(controller); rowText[point.x] = view; } gridView[point.y] = rowText; } gridTable.requestLayout(); } }
From source file:ws.crandell.newspaperpuzzles.wordsearch.view.WordSearchActivity.java
/** * creates a grid of textViews from layout files based on the gridSize * and sets the new textViews to use the controller as their listener * //from w w w. j a v a 2 s . co m * @param gridSize square size of the new grid to make * @param controller the onkeyListener used for the grid's textViews, also holds the gridView an array of the new textView's in the grid */ public void setupViewGrid() { control.setLetter(null); int gridSize = control.getGridSize(); TextViewGridController controller = control.getGridManager(); ViewGroup gridTable = (ViewGroup) this.findViewById(R.id.gridTable); if (gridTable.getChildCount() != gridSize) { if (gridTable.getChildCount() == 0) { gridTable.setKeepScreenOn(true); gridTable.setOnTouchListener(controller); } controller.clearPointDemension(); gridTable.removeAllViews(); Point point = new Point(); controller.setGridView(new TextView[gridSize][]); TextView[][] gridView = controller.getGridView(); for (point.y = 0; point.y < gridSize; point.y++) { this.getLayoutInflater().inflate(R.layout.ws_grid_row, gridTable, true); ViewGroup row = (ViewGroup) gridTable.getChildAt(point.y); TextView[] rowText = new TextView[gridSize]; for (point.x = 0; point.x < gridSize; point.x++) { this.getLayoutInflater().inflate(R.layout.ws_grid_text_view, row, true); TextView view = (TextView) row.getChildAt(point.x); view.setId(ConversionUtil.convertPointToID(point, control.getGridSize())); view.setOnKeyListener(controller); rowText[point.x] = view; } gridView[point.y] = rowText; } gridTable.requestLayout(); } }
From source file:android.car.ui.provider.CarDrawerLayout.java
@Override protected void onFinishInflate() { super.onFinishInflate(); mHasInflated = true;/*www . j av a2 s . c o m*/ setAutoDayNightMode(); setOnGenericMotionListener(new OnGenericMotionListener() { @Override public boolean onGenericMotion(View view, MotionEvent event) { if (getChildCount() == 0) { return false; } if (isDrawerOpen()) { View drawerView = findDrawerView(); ViewGroup viewGroup = (ViewGroup) ((FrameLayout) drawerView).getChildAt(0); return viewGroup.getChildAt(0).onGenericMotionEvent(event); } View contentView = findContentView(); ViewGroup viewGroup = (ViewGroup) ((FrameLayout) contentView).getChildAt(0); return viewGroup.getChildAt(0).onGenericMotionEvent(event); } }); }
From source file:com.base.view.slidemenu.SlideMenu.java
protected final boolean canScrollVertically(View v, int dy, int x, int y) { if (v instanceof ViewGroup) { final ViewGroup viewGroup = (ViewGroup) v; final int scrollX = v.getScrollX(); final int scrollY = v.getScrollY(); final int childCount = viewGroup.getChildCount(); for (int index = 0; index < childCount; index++) { View child = viewGroup.getChildAt(index); final int left = child.getLeft(); final int top = child.getTop(); if (x + scrollX >= left && x + scrollX < child.getRight() && y + scrollY >= top && y + scrollY < child.getBottom() && View.VISIBLE == child.getVisibility() && (ScrollDetectors.canScrollVertical(child, dy) || canScrollVertically(child, dy, x + scrollX - left, y + scrollY - top))) { return true; }/*from ww w . j ava 2 s .co m*/ } } return ViewCompat.canScrollVertically(v, -dy); }
From source file:com.base.view.slidemenu.SlideMenu.java
/** * Detect whether the views inside content are slidable *///from w w w .j a v a 2s . c om protected final boolean canScrollHorizontally(View v, int dx, int x, int y) { if (v instanceof ViewGroup) { final ViewGroup viewGroup = (ViewGroup) v; final int scrollX = v.getScrollX(); final int scrollY = v.getScrollY(); final int childCount = viewGroup.getChildCount(); for (int index = 0; index < childCount; index++) { View child = viewGroup.getChildAt(index); final int left = child.getLeft(); final int top = child.getTop(); if (x + scrollX >= left && x + scrollX < child.getRight() && y + scrollY >= top && y + scrollY < child.getBottom() && View.VISIBLE == child.getVisibility() && (ScrollDetectors.canScrollHorizontal(child, dx) || canScrollHorizontally(child, dx, x + scrollX - left, y + scrollY - top))) { return true; } } } return ViewCompat.canScrollHorizontally(v, -dx); }
From source file:ca.mymenuapp.ui.widgets.SlidingUpPanelLayout.java
/** * Tests scrollability within child views of v given a delta of dx. * * @param v View to test for horizontal scrollability * @param checkV Whether the view v passed should itself be checked for scrollability (true), * or just its children (false)./*from www .j a va2 s . c o m*/ * @param dx Delta scrolled in pixels * @param x X coordinate of the active touch point * @param y Y coordinate of the active touch point * @return true if child views of v can be scrolled by delta of dx. */ protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) { if (v instanceof ViewGroup) { final ViewGroup group = (ViewGroup) v; final int scrollX = v.getScrollX(); final int scrollY = v.getScrollY(); final int count = group.getChildCount(); // Count backwards - let topmost views consume scroll distance first. for (int i = count - 1; i >= 0; i--) { final View child = group.getChildAt(i); if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() && y + scrollY >= child.getTop() && y + scrollY < child.getBottom() && canScroll(child, true, dx, x + scrollX - child.getLeft(), y + scrollY - child.getTop())) { return true; } } } return checkV && ViewCompat.canScrollHorizontally(v, -dx); }
From source file:com.ksharkapps.musicnow.ui.activities.AudioPlayerActivity.java
/** * Sets the font on all TextViews in the ViewGroup. Searches recursively for * all inner ViewGroups as well. Just add a check for any other views you * want to set as well (EditText, etc.)/*from w w w .j ava2 s. c o m*/ */ private void setFont(ViewGroup group, Typeface font) { int count = group.getChildCount(); View v; for (int i = 0; i < count; i++) { v = group.getChildAt(i); if (v instanceof TextView || v instanceof EditText || v instanceof Button) { ((TextView) v).setTypeface(font); } else if (v instanceof ViewGroup) setFont((ViewGroup) v, font); } }
From source file:com.tomeokin.lspush.biz.home.CollectionListAdapter.java
private void setExplorers(ViewGroup container, @Nullable List<User> explorers) { final Context context = container.getContext(); // // TODO: 2016/10/8 performance improve //container.removeAllViews(); //for (User explorer : explorers) { // final ImageView avatar = // (ImageView) LayoutInflater.from(context).inflate(R.layout.layout_item_explorer, container, false); // ImageLoader.loadAvatar(context, avatar, explorer.getImage()); // container.addView(avatar); //}//from w ww . j ava2s .co m final int count = container.getChildCount(); int targetCount = explorers == null ? 0 : explorers.size(); targetCount = targetCount >= 5 ? 5 : targetCount; final LayoutInflater inflater = LayoutInflater.from(context); if (count > targetCount) { container.removeViews(targetCount, count - targetCount); } ImageView avatar; for (int i = 0; i < targetCount; i++) { if (i > count - 1) { // no cache avatar = (ImageView) inflater.inflate(R.layout.layout_item_explorer, container, false); } else { avatar = (ImageView) container.getChildAt(i); } ImageLoader.loadAvatar(context, avatar, explorers.get(i).getImage()); if (avatar.getParent() == null) { container.addView(avatar); } avatar.setTag(R.id.avatar_tag_uid, explorers.get(i).getUid()); avatar.setOnClickListener(mExplorerListener); } }
From source file:com.android.yijiang.kzx.widget.tab.PagerSlidingTabStrip.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { ViewGroup tabViewGroup = getTabsLayout(); // //from ww w . ja v a 2 s . com if (tabViewGroup == null || tabViewGroup.getChildCount() <= 0) { super.onLayout(changed, l, t, r, b); return; } int viewWidth = r - l; // Item if ((measure(tabViewGroup).getMeasuredWidth() < viewWidth) && allowWidthFull) { // ?tabViewGroup?? viewWidth -= tabViewGroup.getPaddingLeft(); viewWidth -= tabViewGroup.getPaddingRight(); if (tabViewGroup.getLayoutParams() instanceof MarginLayoutParams) { MarginLayoutParams tabsLayoutParams = (MarginLayoutParams) tabViewGroup.getLayoutParams(); viewWidth -= tabsLayoutParams.leftMargin; viewWidth -= tabsLayoutParams.rightMargin; } // ??Tab? View tabView; for (int w = 0; w < tabViewGroup.getChildCount(); w++) { tabView = tabViewGroup.getChildAt(w); if (tabView.getLayoutParams() instanceof MarginLayoutParams) { MarginLayoutParams marginLayoutParams = (MarginLayoutParams) tabView.getLayoutParams(); viewWidth -= marginLayoutParams.leftMargin; viewWidth -= marginLayoutParams.rightMargin; } } // ? int averageWidth = viewWidth / tabViewGroup.getChildCount(); int bigTabCount = 0; // ?tab??? for (int w = 0; w < tabViewGroup.getChildCount(); w++) { tabView = tabViewGroup.getChildAt(w); // ???? if (tabView != null && tabView.getMeasuredWidth() > averageWidth) { viewWidth -= tabView.getMeasuredWidth(); bigTabCount++; } } // ? averageWidth = viewWidth / (tabViewGroup.getChildCount() - bigTabCount); // ??Item for (int w = 0; w < tabViewGroup.getChildCount(); w++) { //????? tabView = tabViewGroup.getChildAt(w); if (tabView != null) { ViewGroup.LayoutParams layoutParams = tabView.getLayoutParams(); if (layoutParams != null) { layoutParams.width = tabView.getMeasuredWidth() < averageWidth ? averageWidth : tabView.getMeasuredWidth(); tabView.setLayoutParams(layoutParams); measure(tabView); } } } measure(tabViewGroup); } // ????? currentPosition = viewPager != null ? viewPager.getCurrentItem() : 0; scrollToChild(currentPosition, 0); //?? selectedTab(currentPosition); //?TAB //?tab?Pager for (int w = 0; w < tabViewGroup.getChildCount(); w++) { View itemView = tabViewGroup.getChildAt(w); itemView.setTag(w); itemView.setOnClickListener(this); } super.onLayout(changed, l, t, r, b); }
From source file:android.car.ui.provider.CarDrawerLayout.java
private void updateDrawerAlpha() { float alpha;/*from ww w .j a va 2s . c o m*/ if (mStartedOpen) { alpha = mDrawerFadeInterpolator.getReverseInterpolation(onScreen()); } else { alpha = mDrawerFadeInterpolator.getForwardInterpolation(onScreen()); } ViewGroup drawerView = (ViewGroup) findDrawerView(); int drawerChildCount = drawerView.getChildCount(); for (int i = 0; i < drawerChildCount; i++) { drawerView.getChildAt(i).setAlpha(alpha); } }