List of usage examples for android.view View getWidth
@ViewDebug.ExportedProperty(category = "layout") public final int getWidth()
From source file:com.charon.scrollingtabs.view.ScrollingTabs.java
/** * Add tab view./* ww w . j av a 2 s .c om*/ */ private void initTabView() { int totalWidth = 0; if (mViewPager != null && mTabAdapter != null) { mContainer.removeAllViews(); if (mEqualWidth) { for (int i = 0; i < mViewPager.getAdapter().getCount(); i++) { View tab = mTabAdapter.getView(i); measureView(tab); totalWidth += tab.getWidth(); if (tab.getLayoutParams() != null) { // int width = tab.getLayoutParams().width; // int height = tab.getLayoutParams().height; } else { tab.setLayoutParams(new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 100f)); } if (mTabAdapter.getSeparator() != null && i != mViewPager.getAdapter().getCount() - 1) { isUseSeperator = true; measureView(mTabAdapter.getSeparator()); totalWidth += mTabAdapter.getSeparator().getWidth(); } } if (totalWidth < mWindowWidth) { int count = mViewPager.getAdapter().getCount(); if (isUseSeperator) { tabWidth = (mWindowWidth - (count - 1) * mTabAdapter.getSeparator().getWidth()) / count; } else { tabWidth = mWindowWidth / count; } } } for (int i = 0; i < mViewPager.getAdapter().getCount(); i++) { final View tab = mTabAdapter.getView(i); tab.setTag(i); if (tabWidth != 0) { mContainer.addView(tab, new LinearLayout.LayoutParams(tabWidth, android.widget.LinearLayout.LayoutParams.MATCH_PARENT)); } else { mContainer.addView(tab, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 100f)); } // Segmentation view if (mTabAdapter.getSeparator() != null && i != mViewPager.getAdapter().getCount() - 1) { isUseSeperator = true; mContainer.addView(mTabAdapter.getSeparator()); } // Set click listener on tab. tab.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { int index = (Integer) tab.getTag(); if (mTabClickListener != null) { mTabClickListener.onClick(index); } else { if (mViewPager.getCurrentItem() == index) { selectTab(index); } else { // If ViewPager change the page, the listener // will call selectTab method mViewPager.setCurrentItem(index, true); } } } }); } // Set the current selected tab when first coming. selectTab(mViewPager.getCurrentItem()); } }
From source file:android.support.transition.ChangeBounds.java
private void captureValues(TransitionValues values) { View view = values.view; if (ViewCompat.isLaidOut(view) || view.getWidth() != 0 || view.getHeight() != 0) { values.values.put(PROPNAME_BOUNDS, new Rect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom())); values.values.put(PROPNAME_PARENT, values.view.getParent()); if (mReparent) { values.view.getLocationInWindow(mTempLocation); values.values.put(PROPNAME_WINDOW_X, mTempLocation[0]); values.values.put(PROPNAME_WINDOW_Y, mTempLocation[1]); }//from w w w .ja v a 2s. co m if (mResizeClip) { values.values.put(PROPNAME_CLIP, ViewCompat.getClipBounds(view)); } } }
From source file:be.digitalia.fosdem.widgets.SlidingTabLayout.java
private void scrollToTab(int tabIndex, float positionOffset) { final int tabStripChildCount = mTabStrip.getChildCount(); if (tabStripChildCount == 0 || tabIndex < 0 || tabIndex >= tabStripChildCount) { return;//ww w. j a v a 2s .co m } View selectedChild = mTabStrip.getChildAt(tabIndex); if (selectedChild != null) { int targetScrollX = selectedChild.getLeft() + Math.round(positionOffset * selectedChild.getWidth()) - mTitleOffset; scrollTo(targetScrollX, 0); } }
From source file:com.easemob.helpdeskdemo.ui.SatisfactionActivity.java
private boolean isShouldHideInput(View v, MotionEvent event) { if (v != null && (v instanceof EditText)) { int[] leftTop = { 0, 0 }; // ??location? v.getLocationInWindow(leftTop);/*from w ww . j a va 2s . c o m*/ int left = leftTop[0]; int top = leftTop[1]; int bottom = top + v.getHeight(); int right = left + v.getWidth(); if (event.getX() > left && event.getX() < right && event.getY() > top && event.getY() < bottom) { // ?EditText return false; } else { return true; } } return false; }
From source file:android.hqs.view.pager.indicator.TabPageIndicator.java
private void animateToTab(final int position) { final View tabView = mTabLayout.getChildAt(position); if (mTabSelector != null) { removeCallbacks(mTabSelector);/*from w ww . j a v a 2 s. c o m*/ } mTabSelector = new Runnable() { public void run() { final int scrollPos = tabView.getLeft() - (getWidth() - tabView.getWidth()) / 2; smoothScrollTo(scrollPos, 0); mTabSelector = null; } }; post(mTabSelector); }
From source file:com.ftinc.kit.attributr.ui.widget.StickyRecyclerHeadersElevationDecoration.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override//from w ww. jav a2 s . co m public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) { super.onDrawOver(canvas, parent, state); int orientation = getOrientation(parent); mHeaderRects.clear(); if (parent.getChildCount() > 0 && mAdapter.getItemCount() > 0) { // draw the first visible child's header at the top of the view View firstView = parent.getChildAt(0); int firstPosition = parent.getChildPosition(firstView); if (mAdapter.getHeaderId(firstPosition) > -1) { View firstHeader = getHeaderView(parent, firstPosition); View nextView = getNextView(parent); int translationX = Math.max(parent.getChildAt(0).getLeft() - firstHeader.getWidth(), 0); int translationY = Math.max(parent.getChildAt(0).getTop() - firstHeader.getHeight(), 0); int nextPosition = parent.getChildPosition(nextView); if (nextPosition > 0 && hasNewHeader(nextPosition)) { View secondHeader = getHeaderView(parent, nextPosition); //Translate the topmost header so the next header takes its place, if applicable if (orientation == LinearLayoutManager.VERTICAL && nextView.getTop() - secondHeader.getHeight() - firstHeader.getHeight() < 0) { translationY += nextView.getTop() - secondHeader.getHeight() - firstHeader.getHeight(); } else if (orientation == LinearLayoutManager.HORIZONTAL && nextView.getLeft() - secondHeader.getWidth() - firstHeader.getWidth() < 0) { translationX += nextView.getLeft() - secondHeader.getWidth() - firstHeader.getWidth(); } } boolean shouldDrawShadow = true; if (firstPosition == 0 && (firstView.getTop() == firstHeader.getHeight())) { shouldDrawShadow = false; } if (translationY == 0 && shouldDrawShadow) { ImageView shadow = ButterKnife.findById(firstHeader, R.id.shadow); shadow.setVisibility(View.VISIBLE); } else { ImageView shadow = ButterKnife.findById(firstHeader, R.id.shadow); shadow.setVisibility(View.GONE); } canvas.save(); canvas.translate(translationX, translationY); firstHeader.draw(canvas); canvas.restore(); mHeaderRects.put(firstPosition, new Rect(translationX, translationY, translationX + firstHeader.getWidth(), translationY + firstHeader.getHeight())); } if (parent.getChildCount() > 1 && mAdapter.getItemCount() > 1) { for (int i = 1; i < parent.getChildCount(); i++) { int position = parent.getChildPosition(parent.getChildAt(i)); if (hasNewHeader(position)) { // this header is different than the previous, it must be drawn in the correct place int translationX = 0; int translationY = 0; View header = getHeaderView(parent, position); if (orientation == LinearLayoutManager.VERTICAL) { translationY = parent.getChildAt(i).getTop() - header.getHeight(); } else { translationX = parent.getChildAt(i).getLeft() - header.getWidth(); } // don't render shadow ImageView shadow = ButterKnife.findById(header, R.id.shadow); shadow.setVisibility(View.GONE); canvas.save(); canvas.translate(translationX, translationY); header.draw(canvas); canvas.restore(); mHeaderRects.put(position, new Rect(translationX, translationY, translationX + header.getWidth(), translationY + header.getHeight())); } } } } }
From source file:android.widget.Gallery.java
/** * @return The center of the given view. *///from w w w . j av a 2s . c o m private static int getCenterOfView(View view) { return view.getLeft() + view.getWidth() / 2; }
From source file:at.linuxtage.companion.widgets.SlidingTabLayout.java
void scrollToTab(int tabIndex, float positionOffset) { final int tabStripChildCount = mTabStrip.getChildCount(); if (tabStripChildCount == 0 || tabIndex < 0 || tabIndex >= tabStripChildCount) { return;/*from w w w.j a v a2 s. c o m*/ } View selectedChild = mTabStrip.getChildAt(tabIndex); if (selectedChild != null) { int targetScrollX = selectedChild.getLeft() + Math.round(positionOffset * selectedChild.getWidth()) - mTitleOffset; scrollTo(targetScrollX, 0); } }
From source file:com.benefit.buy.library.viewpagerindicator.TabPageIndicator.java
private void animateToTab(final int position) { final View tabView = mTabLayout.getChildAt(position); if (mTabSelector != null) { removeCallbacks(mTabSelector);// w w w .j a v a 2 s .c om } mTabSelector = new Runnable() { @Override public void run() { final int scrollPos = tabView.getLeft() - ((getWidth() - tabView.getWidth()) / 2); smoothScrollTo(scrollPos, 0); mTabSelector = null; } }; post(mTabSelector); }
From source file:com.foxconn.remote.control.widget.CustomPagerIndicator.java
private void animateToTab(final int position) { final View tabView = mTabLayout.getChildAt(position); if (mTabSelector != null) { removeCallbacks(mTabSelector);/*from w w w . j a v a 2s .com*/ } mTabSelector = new Runnable() { public void run() { // ? final int scrollPos = tabView.getLeft() - (getWidth() - tabView.getWidth()) / 2; smoothScrollTo(scrollPos, 0); mTabSelector = null; } }; post(mTabSelector); }