Java Code Examples for android.widget.LinearLayout.getChildCount()

The following are Jave code examples for showing how to use getChildCount() of the android.widget.LinearLayout class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: LiveGiftLayout   File: GiftControl.java   View Source Code Vote up 6 votes
/**
 * @param giftLayoutParent 存放礼物控件的父容器
 * @param giftLayoutNums   礼物控件的数量
 * @return
 */
public GiftControl setGiftLayout(LinearLayout giftLayoutParent, @NonNull int giftLayoutNums) {
    if (giftLayoutNums <= 0) {
        throw new IllegalArgumentException("GiftFrameLayout数量必须大于0");
    }
    if (giftLayoutParent.getChildCount() > 0) {//如果父容器没有子孩子,就进行添加
        return this;
    }
    mGiftLayoutParent = giftLayoutParent;
    mGiftLayoutMaxNums = giftLayoutNums;
    LayoutTransition transition = new LayoutTransition();
    transition.setAnimator(LayoutTransition.CHANGE_APPEARING,
            transition.getAnimator(LayoutTransition.CHANGE_APPEARING));
    transition.setAnimator(LayoutTransition.APPEARING,
            transition.getAnimator(LayoutTransition.APPEARING));
    transition.setAnimator(LayoutTransition.DISAPPEARING,
            transition.getAnimator(LayoutTransition.CHANGE_APPEARING));
    transition.setAnimator(LayoutTransition.CHANGE_DISAPPEARING,
            transition.getAnimator(LayoutTransition.DISAPPEARING));
    mGiftLayoutParent.setLayoutTransition(transition);

    return this;
}
 
Example 2
Project: GCSApp   File: WheelRecycle.java   View Source Code Vote up 6 votes
/**
 * Recycles items from specified layout.
 * There are saved only items not included to specified range.
 * All the cached items are removed from original layout.
 * 
 * @param layout the layout containing items to be cached
 * @param firstItem the number of first item in layout
 * @param range the range of current wheel items 
 * @return the new value of first item number
 */
public int recycleItems(LinearLayout layout, int firstItem, ItemsRange range) {
	int index = firstItem;
	for (int i = 0; i < layout.getChildCount();) {
		if (!range.contains(index)) {
			recycleView(layout.getChildAt(i), index);
			layout.removeViewAt(i);
			if (i == 0) { // first item
				firstItem++;
			}
		} else {
			i++; // go to next item
		}
		index++;
	}
	return firstItem;
}
 
Example 3
Project: SlotNSlot_Android   File: WheelRecycle.java   View Source Code Vote up 6 votes
/**
 * Recycles items from specified layout.
 * There are saved only items not included to specified range.
 * All the cached items are removed from original layout.
 * 
 * @param layout the layout containing items to be cached
 * @param firstItem the number of first item in layout
 * @param range the range of current wheel items 
 * @return the new value of first item number
 */
public int recycleItems(LinearLayout layout, int firstItem, ItemsRange range) {
	int index = firstItem;
	for (int i = 0; i < layout.getChildCount();) {
		if (!range.contains(index)) {
			recycleView(layout.getChildAt(i), index);
			layout.removeViewAt(i);
			if (i == 0) { // first item
				firstItem++;
			}
		} else {
			i++; // go to next item
		}
		index++;
	}
	return firstItem;
}
 
Example 4
Project: Hotspot-master-devp   File: WheelRecycle.java   View Source Code Vote up 6 votes
/**
 * Recycles items from specified layout.
 * There are saved only items not included to specified range.
 * All the cached items are removed from original layout.
 * 
 * @param layout the layout containing items to be cached
 * @param firstItem the number of first item in layout
 * @param range the range of current wheel items 
 * @return the new value of first item number
 */
public int recycleItems(LinearLayout layout, int firstItem, ItemsRange range) {
	int index = firstItem;
	for (int i = 0; i < layout.getChildCount();) {
		if (!range.contains(index)) {
			recycleView(layout.getChildAt(i), index);
			layout.removeViewAt(i);
			if (i == 0) { // first item
				firstItem++;
			}
		} else {
			i++; // go to next item
		}
		index++;
	}
	return firstItem;
}
 
Example 5
Project: letv   File: TopRecommendFragment.java   View Source Code Vote up 6 votes
private void makeGallerySwitchBackGround(LinearLayout gallerySwtichLayout, int count) {
    int childCount = gallerySwtichLayout.getChildCount();
    if (count > childCount) {
        count -= childCount;
        for (int i = 0; i < count; i++) {
            ImageView itemImageView = new ImageView(getActivity());
            itemImageView.setLayoutParams(new LayoutParams(-2, -2));
            itemImageView.setImageResource(2130838158);
            itemImageView.setPadding(5, 0, 5, 0);
            gallerySwtichLayout.addView(itemImageView, childCount + i);
        }
    }
}
 
Example 6
Project: CoolClock   File: WheelRecycle.java   View Source Code Vote up 6 votes
/**
 * Recycles items from specified layout.
 * There are saved only items not included to specified range.
 * All the cached items are removed from original layout.
 * 
 * @param layout the layout containing items to be cached
 * @param firstItem the number of first item in layout
 * @param range the range of current wheel items 
 * @return the new value of first item number
 */
public int recycleItems(LinearLayout layout, int firstItem, ItemsRange range) {
	int index = firstItem;
	for (int i = 0; i < layout.getChildCount();) {
		if (!range.contains(index)) {
			recycleView(layout.getChildAt(i), index);
			layout.removeViewAt(i);
			if (i == 0) { // first item
				firstItem++;
			}
		} else {
			i++;
		}
		index++;
	}
	return firstItem;
}
 
Example 7
Project: mupdf-android-viewer-nui   File: WheelRecycle.java   View Source Code Vote up 6 votes
/**
 * Recycles items from specified layout.
 * There are saved only items not included to specified range.
 * All the cached items are removed from original layout.
 *
 * @param layout the layout containing items to be cached
 * @param firstItem the number of first item in layout
 * @param range the range of current wheel items
 * @return the new value of first item number
 */
public int recycleItems(LinearLayout layout, int firstItem, ItemsRange range) {
	int index = firstItem;
	for (int i = 0; i < layout.getChildCount();) {
		if (!range.contains(index)) {
			recycleView(layout.getChildAt(i), index);
			layout.removeViewAt(i);
			if (i == 0) { // first item
				firstItem++;
			}
		} else {
			i++; // go to next item
		}
		index++;
	}
	return firstItem;
}
 
Example 8
Project: GitHub   File: ViewHolderFunc.java   View Source Code Vote up 5 votes
public ViewHolderFunc(View itemView) {
    super(itemView);

    LinearLayout root = (LinearLayout) itemView.findViewById(R.id.content_container);
    for (int i = 0; i < root.getChildCount(); i++) {
        for (int z = 0; z < ((ViewGroup) root.getChildAt(i)).getChildCount(); z++) {
            ((ViewGroup) root.getChildAt(i)).getChildAt(z).setOnClickListener(this);
        }
    }
}
 
Example 9
Project: mobile-store   File: AppSecurityPermissions.java   View Source Code Vote up 5 votes
public View getPermissionsView(int which) {
    LinearLayout permsView = (LinearLayout) inflater.inflate(R.layout.app_perms_summary, null);
    LinearLayout displayList = (LinearLayout) permsView.findViewById(R.id.perms_list);
    View noPermsView = permsView.findViewById(R.id.no_permissions);

    displayPermissions(permGroupsList, displayList, which);
    if (displayList.getChildCount() <= 0) {
        noPermsView.setVisibility(View.VISIBLE);
    }

    return permsView;
}
 
Example 10
Project: FastAndroid   File: CallUserGridView.java   View Source Code Vote up 5 votes
public void removeChild(String childId) {
    int containerCount = linearLayout.getChildCount();

    LinearLayout lastContainer = null;
    List<LinearLayout> containerList = new ArrayList<>();
    for (int i = 0; i < containerCount; i++) {
        LinearLayout container = (LinearLayout) linearLayout.getChildAt(i);
        containerList.add(container);
    }
    for (LinearLayout resultContainer : containerList) {
        if (lastContainer == null) {
            LinearLayout child = (LinearLayout) resultContainer.findViewWithTag(childId);
            if (child != null) {
                resultContainer.removeView(child);
                if (resultContainer.getChildCount() == 0) {
                    linearLayout.removeView(resultContainer);
                    break;
                } else {
                    lastContainer = resultContainer;
                }
            }
        } else {
            View view = resultContainer.getChildAt(0);
            resultContainer.removeView(view);
            lastContainer.addView(view);
            if (resultContainer.getChildCount() == 0) {
                linearLayout.removeView(resultContainer);
                break;
            } else {
                lastContainer = resultContainer;
            }
        }
    }
}
 
Example 11
Project: edslider   File: EdSliderView.java   View Source Code Vote up 5 votes
/**
 * Animate the views too look more lively
 */
public void dismiss()
{
    LinearLayout layout = (LinearLayout) getChildAt(0);

    for (int i = 0; i < layout.getChildCount(); i++)
    {
        View v = layout.getChildAt(i);
        v.setScaleX(1);
        v.setScaleY(1);
        v.animate().cancel();
        v.animate().translationY(isReversed ? -v.getHeight() :v.getHeight())
                .scaleX(0).scaleY(0).setDuration(100)
                .setStartDelay(80 * i)
                .setInterpolator(null)
                .start();
    }
    // hide view when finish animating
    new Handler().postDelayed(new Runnable()
    {
        @Override
        public void run()
        {
            manager.dismiss();
        }
    }, 150 * layout.getChildCount());
}
 
Example 12
Project: letv   File: MyMessageTabPageIndicator.java   View Source Code Vote up 5 votes
public void setCurrentItem(int item) {
    if (this.mViewPager != null) {
        if (!(item == -1 || this.mSelectedTabIndex == item)) {
            this.mViewPager.setCurrentItem(item);
        }
        this.mSelectedTabIndex = item;
        int tabCount = this.mTabLayout.getChildCount();
        int i = 0;
        while (i < tabCount) {
            LinearLayout childLayout = (LinearLayout) this.mTabLayout.getChildAt(i);
            for (int j = 0; j < childLayout.getChildCount(); j++) {
                boolean isSelected = i == item;
                View view = childLayout.getChildAt(j);
                if (view instanceof TabView) {
                    view.setSelected(isSelected);
                    if (isSelected) {
                        animateToTab(item);
                        ((TabView) view).setTextColor(this.mContext.getResources().getColor(2131493202));
                    } else {
                        ((TabView) view).setTextColor(this.mContext.getResources().getColor(2131493237));
                    }
                } else if (isSelected) {
                    view.setBackgroundColor(this.mContext.getResources().getColor(2131493202));
                } else {
                    view.setBackgroundDrawable(null);
                }
            }
            i++;
        }
    }
}
 
Example 13
Project: ChartProgressBar-Android   File: ChartProgressBar.java   View Source Code Vote up 5 votes
public void resetBarValues() {

		if (oldFrameLayout != null)
			removeClickedBar();

		final int barsCount = ((LinearLayout) this.getChildAt(0)).getChildCount();

		for (int i = 0; i < barsCount; i++) {

			FrameLayout rootFrame = (FrameLayout) ((LinearLayout) this.getChildAt(0)).getChildAt(i);
			int rootChildCount = rootFrame.getChildCount();

			for (int j = 0; j < rootChildCount; j++) {

				View childView = rootFrame.getChildAt(j);

				if (childView instanceof LinearLayout) {
					//bar
					LinearLayout barContainerLinear = ((LinearLayout) childView);
					int barContainerCount = barContainerLinear.getChildCount();

					for (int k = 0; k < barContainerCount; k++) {

						View view = barContainerLinear.getChildAt(k);

						if (view instanceof Bar) {
							BarAnimation anim = new BarAnimation(((Bar) view), 0, (int) (mDataList.get(i).getBarValue() * 100));
							anim.setDuration(250);
							((Bar) view).startAnimation(anim);
						}
					}
				}


			}
		}
		isBarsEmpty = false;
	}
 
Example 14
Project: ChartProgressBar-Android   File: ChartProgressBar.java   View Source Code Vote up 5 votes
public void removeBarValues() {

		if (oldFrameLayout != null)
			removeClickedBar();

		final int barsCount = ((LinearLayout) this.getChildAt(0)).getChildCount();

		for (int i = 0; i < barsCount; i++) {

			FrameLayout rootFrame = (FrameLayout) ((LinearLayout) this.getChildAt(0)).getChildAt(i);
			int rootChildCount = rootFrame.getChildCount();

			for (int j = 0; j < rootChildCount; j++) {

				View childView = rootFrame.getChildAt(j);

				if (childView instanceof LinearLayout) {
					//bar
					LinearLayout barContainerLinear = ((LinearLayout) childView);
					int barContainerCount = barContainerLinear.getChildCount();

					for (int k = 0; k < barContainerCount; k++) {

						View view = barContainerLinear.getChildAt(k);

						if (view instanceof Bar) {
							BarAnimation anim = new BarAnimation(((Bar) view), (int) (mDataList.get(i).getBarValue() * 100), 0);
							anim.setDuration(250);
							((Bar) view).startAnimation(anim);
						}
					}
				}
			}


		}
		isBarsEmpty = true;
	}
 
Example 15
Project: MaterialDesignDemo   File: TabLayoutActivity.java   View Source Code Vote up 4 votes
@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab_layout);
        mTabLayout = (TabLayout) findViewById(R.id.tabLayout);

        // 手动创建Tab
//        for (int i = 0; i < title.length; i++) {
//            TabLayout.Tab tab = mTabLayout.newTab();
//            tab.setText(title[i]);
////            tab.setIcon(R.mipmap.ic_launcher);//icon会显示在文字上面
//            mTabLayout.addTab(tab);
//        }

        // TabLayout与ViewPager结合使用
        mViewPager = (ViewPager) findViewById(R.id.viewPager);
        MyViewPagerAdapter adapter = new MyViewPagerAdapter(getSupportFragmentManager());
        mViewPager.setAdapter(adapter);
//        // 适配器必须重写getPageTitle()方法
//        mTabLayout.setTabsFromPagerAdapter(adapter);
//        // 监听TabLayout的标签选择,当标签选中时ViewPager切换
//        mTabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
//        // 监听ViewPager的页面切换,当页面切换时TabLayout的标签跟着切换
//        mViewPager.setOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
        // 关联TabLayout与ViewPager,且适配器必须重写getPageTitle()方法
        mTabLayout.setupWithViewPager(mViewPager);


        mLinearLayout = (LinearLayout) mTabLayout.getChildAt(0);
        // 在所有子控件的中间显示分割线(还可能只显示顶部、尾部和不显示分割线)
        mLinearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
        // 设置分割线的距离本身(LinearLayout)的内间距
        mLinearLayout.setDividerPadding(50);
        // 设置分割线的样式
        mLinearLayout.setDividerDrawable(ContextCompat.getDrawable(this, R.drawable.divider_vertical));
        mLinearLayout.setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));


        // 为TabLayout设置不同状态下的字体大小(并不能成功)
//        for (int i = 0; i < mTabLayout.getTabCount(); i++) {
//            ((TextView) ((LinearLayout) mLinearLayout.getChildAt(i)).getChildAt(1)).setTextSize(10);
////            ((TextView) ((LinearLayout) ((LinearLayout) mTabLayout.getChildAt(0)).getChildAt(i)).getChildAt(0)).setTextSize(12);
//        }
//        ((TextView) ((LinearLayout) mLinearLayout.getChildAt(mTabLayout.getSelectedTabPosition())).getChildAt(1)).setTextSize(30);
//
//        mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
//            @Override
//            public void onTabSelected(TabLayout.Tab tab) {
//                ((TextView) ((LinearLayout) mLinearLayout.getChildAt(tab.getPosition())).getChildAt(1)).setTextSize(30);
//            }
//
//            @Override
//            public void onTabUnselected(TabLayout.Tab tab) {
//                ((TextView) ((LinearLayout) mLinearLayout.getChildAt(tab.getPosition())).getChildAt(1)).setTextSize(10);
//            }
//
//            @Override
//            public void onTabReselected(TabLayout.Tab tab) {
//
//            }
//        });


        // 自定义指示器(Indicator)的“长度”的两种方法
        // 方法一:反射
//        setIndicator(mTabLayout,10,10);
        // 方法二:查找子控件
        int left = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, Resources.getSystem().getDisplayMetrics());
        int right = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, Resources.getSystem().getDisplayMetrics());
        for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
            View tabView = mLinearLayout.getChildAt(0);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1);
            params.leftMargin = left;
            params.rightMargin = right;
            tabView.setLayoutParams(params);
        }
    }
 
Example 16
Project: OSchina_resources_android   File: ShakePresentActivity.java   View Source Code Vote up 4 votes
private void setState(LinearLayout layout, boolean selected) {
    for (int i = 0; i < layout.getChildCount(); i++) {
        layout.getChildAt(i).setSelected(selected);
    }
}
 
Example 17
Project: ChartProgressBar-Android   File: ChartProgressBar.java   View Source Code Vote up 4 votes
public void disableBar(int index) {

		final int barsCount = ((LinearLayout) this.getChildAt(0)).getChildCount();

		for (int i = 0; i < barsCount; i++) {

			FrameLayout rootFrame = (FrameLayout) ((LinearLayout) this.getChildAt(0)).getChildAt(i);

			int rootChildCount = rootFrame.getChildCount();

			for (int j = 0; j < rootChildCount; j++) {

				if ((int) rootFrame.getTag() != index)
					continue;

				rootFrame.setEnabled(false);
				rootFrame.setClickable(false);

				View childView = rootFrame.getChildAt(j);
				if (childView instanceof LinearLayout) {
					//bar
					LinearLayout barContainerLinear = ((LinearLayout) childView);
					int barContainerCount = barContainerLinear.getChildCount();

					for (int k = 0; k < barContainerCount; k++) {

						View view = barContainerLinear.getChildAt(k);

						if (view instanceof Bar) {

							Bar bar = (Bar) view;

							LayerDrawable layerDrawable = (LayerDrawable) bar.getProgressDrawable();
							layerDrawable.mutate();

							ScaleDrawable scaleDrawable = (ScaleDrawable) layerDrawable.getDrawable(1);

							GradientDrawable progressLayer = (GradientDrawable) scaleDrawable.getDrawable();

							if (progressLayer != null) {

								if (mProgressDisableColor > 0)
									progressLayer.setColor(ContextCompat.getColor(mContext, mProgressDisableColor));
								else
									progressLayer.setColor(ContextCompat.getColor(mContext, android.R.color.darker_gray));
							}
						} else {
							TextView titleTxtView = (TextView) view;
							if (mProgressDisableColor > 0)
								titleTxtView.setTextColor(ContextCompat.getColor(mContext, mProgressDisableColor));
							else
								titleTxtView.setTextColor(ContextCompat.getColor(mContext, android.R.color.darker_gray));
						}
					}
				}
			}
		}
	}
 
Example 18
Project: ChartProgressBar-Android   File: ChartProgressBar.java   View Source Code Vote up 4 votes
public void enableBar(int index) {

		final int barsCount = ((LinearLayout) this.getChildAt(0)).getChildCount();

		for (int i = 0; i < barsCount; i++) {

			FrameLayout rootFrame = (FrameLayout) ((LinearLayout) this.getChildAt(0)).getChildAt(i);

			int rootChildCount = rootFrame.getChildCount();

			for (int j = 0; j < rootChildCount; j++) {

				if ((int) rootFrame.getTag() != index)
					continue;

				rootFrame.setEnabled(true);
				rootFrame.setClickable(true);

				View childView = rootFrame.getChildAt(j);
				if (childView instanceof LinearLayout) {
					//bar
					LinearLayout barContainerLinear = ((LinearLayout) childView);
					int barContainerCount = barContainerLinear.getChildCount();

					for (int k = 0; k < barContainerCount; k++) {

						View view = barContainerLinear.getChildAt(k);

						if (view instanceof Bar) {

							Bar bar = (Bar) view;

							LayerDrawable layerDrawable = (LayerDrawable) bar.getProgressDrawable();
							layerDrawable.mutate();

							ScaleDrawable scaleDrawable = (ScaleDrawable) layerDrawable.getDrawable(1);

							GradientDrawable progressLayer = (GradientDrawable) scaleDrawable.getDrawable();

							if (progressLayer != null) {

								if (mProgressColor > 0)
									progressLayer.setColor(ContextCompat.getColor(mContext, mProgressColor));
								else
									progressLayer.setColor(ContextCompat.getColor(mContext, android.R.color.darker_gray));
							}
						} else {
							TextView titleTxtView = (TextView) view;
							if (mProgressDisableColor > 0)
								titleTxtView.setTextColor(ContextCompat.getColor(mContext, mBarTitleColor));
							else
								titleTxtView.setTextColor(ContextCompat.getColor(mContext, android.R.color.darker_gray));
						}
					}
				}
			}
		}
	}
 
Example 19
Project: quidditchtimekeeper   File: GameActivity.java   View Source Code Vote up 4 votes
public int getChildHeight(CustomScrollView scrollView)
{
    LinearLayout ll = (LinearLayout) scrollView.getChildAt(0);
    return ll.getHeight()/ll.getChildCount();
}
 
Example 20
Project: microMathematics   File: FormulaTerm.java   View Source Code Vote up 4 votes
/**
 * Procedure deletes argument layout for given term and returns the previous term
 */
protected TermField deleteArgument(TermField owner, String sep, boolean storeUndoState)
{
    // target layout where terms will be deleted
    View expandable = owner.getLayout();
    if (expandable == null)
    {
        return null;
    }
    LinearLayout expandableLayout = (LinearLayout) expandable;

    // view index of the field within the parent layout
    int startIndex = ViewUtils.getViewIndex(expandableLayout, owner.getEditText());
    if (startIndex < 0)
    {
        return null;
    }

    // how much views shall be deleted:
    int count = 1;
    {
        final String termKey = getContext().getResources().getString(R.string.formula_arg_term_key);
        final boolean firstTerm = owner.getTermKey().equals(termKey + String.valueOf(1));
        if (firstTerm && startIndex + 1 < expandableLayout.getChildCount()
                && expandableLayout.getChildAt(startIndex + 1) instanceof CustomTextView)
        {
            final CustomTextView next = ((CustomTextView) expandableLayout.getChildAt(startIndex + 1));
            if (next.getText().toString().equals(sep))
            {
                count++;
            }
        }
        else if (!firstTerm && startIndex >= 1
                && expandableLayout.getChildAt(startIndex - 1) instanceof CustomTextView)
        {
            final CustomTextView prev = ((CustomTextView) expandableLayout.getChildAt(startIndex - 1));
            if (prev.getText().toString().equals(sep))
            {
                startIndex--;
                count++;
            }
        }
    }

    if (storeUndoState && parentField != null)
    {
        getFormulaList().getUndoState().addEntry(parentField.getState());
    }
    int prevIndex = terms.indexOf(owner);
    prevIndex--;
    terms.remove(owner);
    expandableLayout.removeViews(startIndex, count);
    reIndexTerms();

    return (prevIndex >= 0) ? terms.get(prevIndex) : null;
}