Java Code Examples for android.view.Gravity#CENTER_HORIZONTAL
The following examples show how to use
android.view.Gravity#CENTER_HORIZONTAL .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecyclerViewHeader.java From Android-Application-ZJB with Apache License 2.0 | 7 votes |
private void setupAlignment(RecyclerView recycler) { if (!mAlreadyAligned) { //setting alignment of header ViewGroup.LayoutParams currentParams = getLayoutParams(); FrameLayout.LayoutParams newHeaderParams; int width = ViewGroup.LayoutParams.WRAP_CONTENT; int height = ViewGroup.LayoutParams.WRAP_CONTENT; int gravity = (mReversed ? Gravity.BOTTOM : Gravity.TOP) | Gravity.CENTER_HORIZONTAL; if (currentParams != null) { newHeaderParams = new FrameLayout.LayoutParams(getLayoutParams()); //to copy all the margins newHeaderParams.width = width; newHeaderParams.height = height; newHeaderParams.gravity = gravity; } else { newHeaderParams = new FrameLayout.LayoutParams(width, height, gravity); } RecyclerViewHeader.this.setLayoutParams(newHeaderParams); //setting alignment of recycler FrameLayout newRootParent = new FrameLayout(recycler.getContext()); newRootParent.setLayoutParams(recycler.getLayoutParams()); ViewParent currentParent = recycler.getParent(); if (currentParent instanceof ViewGroup) { int indexWithinParent = ((ViewGroup) currentParent).indexOfChild(recycler); ((ViewGroup) currentParent).removeViewAt(indexWithinParent); recycler.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); newRootParent.addView(recycler); newRootParent.addView(RecyclerViewHeader.this); ((ViewGroup) currentParent).addView(newRootParent, indexWithinParent); } } }
Example 2
Source File: HeaderAndFooterViewUtil.java From FamiliarRecyclerView with MIT License | 6 votes |
public static View getFooterView(Context context, boolean isVertical, int bgColor, String text) { FrameLayout footer1 = new FrameLayout(context); if (isVertical) { footer1.setLayoutParams(new FamiliarRecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); // vertical } else { footer1.setLayoutParams(new FamiliarRecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); // horizontal } footer1.setBackgroundColor(bgColor); TextView footerviewContent1 = new TextView(context); FrameLayout.LayoutParams footerviewContent1Params; if (isVertical) { footerviewContent1Params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, dip2px(context, 150)); } else { footerviewContent1Params = new FrameLayout.LayoutParams(dip2px(context, 150), ViewGroup.LayoutParams.WRAP_CONTENT); } footerviewContent1Params.gravity = Gravity.CENTER_HORIZONTAL| Gravity.CENTER_VERTICAL; footerviewContent1.setLayoutParams(footerviewContent1Params); footerviewContent1.setGravity(Gravity.CENTER); footerviewContent1.setText(text); footer1.addView(footerviewContent1); return footer1; }
Example 3
Source File: PostFragment.java From redgram-for-reddit with GNU General Public License v3.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.preview_post_fragment, container, false); ButterKnife.inject(this, view); String json = getArguments().getString(getResources().getString(R.string.main_data_key)); postItem = new Gson().fromJson(json, PostItem.class); String content = postItem.getText(); if(content.length() > 0){ mContent.setText(content); }else{ FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); params.gravity = Gravity.CENTER_HORIZONTAL; params.setMargins(0, 100, 0, 0); mContent.setLayoutParams(params); } return view; }
Example 4
Source File: FollowList.java From WeCenterMobile-Android with GNU General Public License v2.0 | 5 votes |
public PRTHeader(Context context) { super(context); setOrientation(VERTICAL); LinearLayout llInner = new LinearLayout(context); LinearLayout.LayoutParams lpInner = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpInner.gravity = Gravity.CENTER_HORIZONTAL; addView(llInner, lpInner); ivArrow = new RotateImageView(context); int resId = getBitmapRes(context, "ssdk_oks_ptr_ptr"); if (resId > 0) { ivArrow.setImageResource(resId); } int dp_32 = dipToPx(context, 32); LayoutParams lpIv = new LayoutParams(dp_32, dp_32); lpIv.gravity = Gravity.CENTER_VERTICAL; llInner.addView(ivArrow, lpIv); pbRefreshing = new ProgressBar(context); llInner.addView(pbRefreshing, lpIv); pbRefreshing.setVisibility(View.GONE); tvHeader = new TextView(getContext()); tvHeader.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); tvHeader.setGravity(Gravity.CENTER); int dp_10 = cn.sharesdk.framework.utils.R.dipToPx(getContext(), 10); tvHeader.setPadding(dp_10, dp_10, dp_10, dp_10); tvHeader.setTextColor(0xff000000); LayoutParams lpTv = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpTv.gravity = Gravity.CENTER_VERTICAL; llInner.addView(tvHeader, lpTv); }
Example 5
Source File: PRTHeader.java From Social with Apache License 2.0 | 5 votes |
public PRTHeader(Context context) { super(context); int[] size = R.getScreenSize(context); float screenWidth = size[0] < size[1] ? size[0] : size[1]; float ratio = screenWidth / DESIGN_SCREEN_WIDTH; setOrientation(VERTICAL); LinearLayout llInner = new LinearLayout(context); LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.CENTER_HORIZONTAL; addView(llInner, lp); ivArrow = new RotateImageView(context); int resId = R.getBitmapRes(context, "ssdk_oks_ptr_ptr"); if (resId > 0) { ivArrow.setImageResource(resId); } int avatarWidth = (int) (ratio * DESIGN_AVATAR_WIDTH); lp = new LayoutParams(avatarWidth, avatarWidth); lp.gravity = Gravity.CENTER_VERTICAL; int avataPadding = (int) (ratio * DESIGN_AVATAR_PADDING); lp.topMargin = lp.bottomMargin = avataPadding; llInner.addView(ivArrow, lp); pbRefreshing = new ProgressBar(context); resId = R.getBitmapRes(context, "ssdk_oks_classic_progressbar"); Drawable pbdrawable = context.getResources().getDrawable(resId); pbRefreshing.setIndeterminateDrawable(pbdrawable); llInner.addView(pbRefreshing, lp); pbRefreshing.setVisibility(View.GONE); tvHeader = new TextView(getContext()); tvHeader.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); tvHeader.setPadding(avataPadding, 0, avataPadding, 0); tvHeader.setTextColor(0xff09bb07); lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.CENTER_VERTICAL; llInner.addView(tvHeader, lp); }
Example 6
Source File: HoloCircularProgressBar.java From UltimateAndroid with Apache License 2.0 | 5 votes |
/** * Compute insets. * * <pre> * ______________________ * |_________dx/2_________| * |......| /'''''\|......| * |-dx/2-|| View ||-dx/2-| * |______| \_____/|______| * |________ dx/2_________| * </pre> * * @param dx * the dx the horizontal unfilled space * @param dy * the dy the horizontal unfilled space */ @SuppressLint("NewApi") private void computeInsets(final int dx, final int dy) { final int layoutDirection; int absoluteGravity = mGravity; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { layoutDirection = getLayoutDirection(); absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection); } switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.LEFT: mHorizontalInset = 0; break; case Gravity.RIGHT: mHorizontalInset = dx; break; case Gravity.CENTER_HORIZONTAL: default: mHorizontalInset = dx / 2; break; } switch (absoluteGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.TOP: mVerticalInset = 0; break; case Gravity.BOTTOM: mVerticalInset = dy; break; case Gravity.CENTER_VERTICAL: default: mVerticalInset = dy / 2; break; } }
Example 7
Source File: BottomVpIndicatorHolder.java From DialogUtil with Apache License 2.0 | 5 votes |
@Override protected View setRootView(Context context) { mLinearLayout = new LinearLayout(context); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT); params.bottomMargin = ScreenUtil.dip2px(10); params.gravity = Gravity.CENTER_HORIZONTAL; mLinearLayout.setLayoutParams(params); dots = new ArrayList<>(); return mLinearLayout; }
Example 8
Source File: PullToRefreshListView.java From GifAssistant with Apache License 2.0 | 5 votes |
@Override protected void handleStyledAttributes(TypedArray a) { super.handleStyledAttributes(a); mListViewExtrasEnabled = a.getBoolean(R.styleable.PullToRefresh_ptrListViewExtrasEnabled, true); if (mListViewExtrasEnabled) { final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL); // Create Loading Views ready for use later FrameLayout frame = new FrameLayout(getContext()); mHeaderLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_START, a); mHeaderLoadingView.setVisibility(View.GONE); frame.addView(mHeaderLoadingView, lp); mRefreshableView.addHeaderView(frame, null, false); mLvFooterLoadingFrame = new FrameLayout(getContext()); mFooterLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_END, a); mFooterLoadingView.setVisibility(View.GONE); mLvFooterLoadingFrame.addView(mFooterLoadingView, lp); /** * If the value for Scrolling While Refreshing hasn't been * explicitly set via XML, enable Scrolling While Refreshing. */ if (!a.hasValue(R.styleable.PullToRefresh_ptrScrollingWhileRefreshingEnabled)) { setScrollingWhileRefreshingEnabled(true); } } }
Example 9
Source File: PullToRefreshPinnedSectionListView.java From PullToRefresh-PinnedSection-ListView with MIT License | 5 votes |
@Override protected void handleStyledAttributes(TypedArray a) { super.handleStyledAttributes(a); mListViewExtrasEnabled = a.getBoolean(R.styleable.PullToRefresh_ptrListViewExtrasEnabled, true); if (mListViewExtrasEnabled) { final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL); // Create Loading Views ready for use later FrameLayout frame = new FrameLayout(getContext()); mHeaderLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_START, a); mHeaderLoadingView.setVisibility(View.GONE); frame.addView(mHeaderLoadingView, lp); mRefreshableView.addHeaderView(frame, null, false); mLvFooterLoadingFrame = new FrameLayout(getContext()); mFooterLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_END, a); mFooterLoadingView.setVisibility(View.GONE); mLvFooterLoadingFrame.addView(mFooterLoadingView, lp); /** * If the value for Scrolling While Refreshing hasn't been * explicitly set via XML, enable Scrolling While Refreshing. */ if (!a.hasValue(R.styleable.PullToRefresh_ptrScrollingWhileRefreshingEnabled)) { setScrollingWhileRefreshingEnabled(true); } } }
Example 10
Source File: BottomSheet.java From AndroidBottomSheet with Apache License 2.0 | 5 votes |
/** * Creates and returns the layout params, which should be used to show the bottom sheet's root * view. * * @return The layout params, which have been created, as an instance of the class {@link * android.widget.FrameLayout.LayoutParams } */ private FrameLayout.LayoutParams createRootViewLayoutParams() { FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; return layoutParams; }
Example 11
Source File: FollowList.java From AndroidLinkup with GNU General Public License v2.0 | 5 votes |
public PRTHeader(Context context) { super(context); setOrientation(VERTICAL); LinearLayout llInner = new LinearLayout(context); LinearLayout.LayoutParams lpInner = new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpInner.gravity = Gravity.CENTER_HORIZONTAL; addView(llInner, lpInner); ivArrow = new RotateImageView(context); int resId = getBitmapRes(context, "ssdk_oks_ptr_ptr"); if (resId > 0) { ivArrow.setImageResource(resId); } int dp_32 = dipToPx(context, 32); LayoutParams lpIv = new LayoutParams(dp_32, dp_32); lpIv.gravity = Gravity.CENTER_VERTICAL; llInner.addView(ivArrow, lpIv); pbRefreshing = new ProgressBar(context); llInner.addView(pbRefreshing, lpIv); pbRefreshing.setVisibility(View.GONE); tvHeader = new TextView(getContext()); tvHeader.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); tvHeader.setGravity(Gravity.CENTER); int dp_10 = cn.sharesdk.framework.utils.R.dipToPx(getContext(), 10); tvHeader.setPadding(dp_10, dp_10, dp_10, dp_10); tvHeader.setTextColor(0xff000000); LayoutParams lpTv = new LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); lpTv.gravity = Gravity.CENTER_VERTICAL; llInner.addView(tvHeader, lpTv); }
Example 12
Source File: ImageLayout.java From ImageLayout with Apache License 2.0 | 5 votes |
public void setGravity(int newValue) { if (fitter != null && gravity == newValue) { return; } if ((newValue & Gravity.HORIZONTAL_GRAVITY_MASK) == 0) { newValue |= Gravity.CENTER_HORIZONTAL; } if ((newValue & Gravity.VERTICAL_GRAVITY_MASK) == 0) { newValue |= Gravity.CENTER_VERTICAL; } gravity = newValue; rebuildFitter(); }
Example 13
Source File: PullToRefreshListView.java From bmob-android-demo-paging with GNU General Public License v3.0 | 5 votes |
@Override protected void handleStyledAttributes(TypedArray a) { super.handleStyledAttributes(a); mListViewExtrasEnabled = a.getBoolean(R.styleable.PullToRefresh_ptrListViewExtrasEnabled, true); if (mListViewExtrasEnabled) { final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL); // Create Loading Views ready for use later FrameLayout frame = new FrameLayout(getContext()); mHeaderLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_START, a); mHeaderLoadingView.setVisibility(View.GONE); frame.addView(mHeaderLoadingView, lp); mRefreshableView.addHeaderView(frame, null, false); mLvFooterLoadingFrame = new FrameLayout(getContext()); mFooterLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_END, a); mFooterLoadingView.setVisibility(View.GONE); mLvFooterLoadingFrame.addView(mFooterLoadingView, lp); /** * If the value for Scrolling While Refreshing hasn't been * explicitly set via XML, enable Scrolling While Refreshing. */ if (!a.hasValue(R.styleable.PullToRefresh_ptrScrollingWhileRefreshingEnabled)) { setScrollingWhileRefreshingEnabled(true); } } }
Example 14
Source File: Toolbar.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private int getChildHorizontalGravity(int gravity) { final int ld = getLayoutDirection(); final int absGrav = Gravity.getAbsoluteGravity(gravity, ld); final int hGrav = absGrav & Gravity.HORIZONTAL_GRAVITY_MASK; switch (hGrav) { case Gravity.LEFT: case Gravity.RIGHT: case Gravity.CENTER_HORIZONTAL: return hGrav; default: return ld == LAYOUT_DIRECTION_RTL ? Gravity.RIGHT : Gravity.LEFT; } }
Example 15
Source File: LazyViewPager.java From AndroidBase with Apache License 2.0 | 4 votes |
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mInLayout = true; populate(); mInLayout = false; final int count = getChildCount(); int width = r - l; int height = b - t; int paddingLeft = getPaddingLeft(); int paddingTop = getPaddingTop(); int paddingRight = getPaddingRight(); int paddingBottom = getPaddingBottom(); final int scrollX = getScrollX(); int decorCount = 0; for (int i = 0; i < count; i++) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); ItemInfo ii; int childLeft = 0; int childTop = 0; if (lp.isDecor) { final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK; final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (hgrav) { default: childLeft = paddingLeft; break; case Gravity.LEFT: childLeft = paddingLeft; paddingLeft += child.getMeasuredWidth(); break; case Gravity.CENTER_HORIZONTAL: childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft); break; case Gravity.RIGHT: childLeft = width - paddingRight - child.getMeasuredWidth(); paddingRight += child.getMeasuredWidth(); break; } switch (vgrav) { default: childTop = paddingTop; break; case Gravity.TOP: childTop = paddingTop; paddingTop += child.getMeasuredHeight(); break; case Gravity.CENTER_VERTICAL: childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop); break; case Gravity.BOTTOM: childTop = height - paddingBottom - child.getMeasuredHeight(); paddingBottom += child.getMeasuredHeight(); break; } childLeft += scrollX; decorCount++; child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(), childTop + child.getMeasuredHeight()); } else if ((ii = infoForChild(child)) != null) { int loff = (width + mPageMargin) * ii.position; childLeft = paddingLeft + loff; childTop = paddingTop; if (DEBUG) Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object + ":" + childLeft + "," + childTop + " " + child.getMeasuredWidth() + "x" + child.getMeasuredHeight()); child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(), childTop + child.getMeasuredHeight()); } } } mTopPageBounds = paddingTop; mBottomPageBounds = height - paddingBottom; mDecorChildCount = decorCount; mFirstLayout = false; }
Example 16
Source File: BottomSheetLayout.java From Expert-Android-Programming with MIT License | 4 votes |
private int getGravity(int gravityEnum) { return (gravityEnum == 0 ? Gravity.START : gravityEnum == 1 ? Gravity.CENTER_HORIZONTAL : Gravity.END) | Gravity.CENTER_VERTICAL; }
Example 17
Source File: LinearLayout.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * Position the children during a layout pass if the orientation of this * LinearLayout is set to {@link #VERTICAL}. * * @see #getOrientation() * @see #setOrientation(int) * @see #onLayout(boolean, int, int, int, int) * @param left * @param top * @param right * @param bottom */ void layoutVertical(int left, int top, int right, int bottom) { final int paddingLeft = mPaddingLeft; int childTop; int childLeft; // Where right end of child should go final int width = right - left; int childRight = width - mPaddingRight; // Space available for child int childSpace = width - paddingLeft - mPaddingRight; final int count = getVirtualChildCount(); final int majorGravity = mGravity & Gravity.VERTICAL_GRAVITY_MASK; final int minorGravity = mGravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK; switch (majorGravity) { case Gravity.BOTTOM: // mTotalLength contains the padding already childTop = mPaddingTop + bottom - top - mTotalLength; break; // mTotalLength contains the padding already case Gravity.CENTER_VERTICAL: childTop = mPaddingTop + (bottom - top - mTotalLength) / 2; break; case Gravity.TOP: default: childTop = mPaddingTop; break; } for (int i = 0; i < count; i++) { final View child = getVirtualChildAt(i); if (child == null) { childTop += measureNullChild(i); } else if (child.getVisibility() != GONE) { final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); final LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child.getLayoutParams(); int gravity = lp.gravity; if (gravity < 0) { gravity = minorGravity; } final int layoutDirection = getLayoutDirection(); final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection); switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: childLeft = paddingLeft + ((childSpace - childWidth) / 2) + lp.leftMargin - lp.rightMargin; break; case Gravity.RIGHT: childLeft = childRight - childWidth - lp.rightMargin; break; case Gravity.LEFT: default: childLeft = paddingLeft + lp.leftMargin; break; } if (hasDividerBeforeChildAt(i)) { childTop += mDividerHeight; } childTop += lp.topMargin; setChildFrame(child, childLeft, childTop + getLocationOffset(child), childWidth, childHeight); childTop += childHeight + lp.bottomMargin + getNextLocationOffset(child); i += getChildrenSkipCount(child, i); } } }
Example 18
Source File: WidgetPickerActivity.java From AcDisplay with GNU General Public License v2.0 | 4 votes |
private void updateAppWidgetViewIfNeeded() { int id = mConfig.getCustomWidgetId(); if (!AppWidgetUtils.isValidId(id)) { mHostViewNeedsReInflate = false; // Remove current app widget. deleteCurrentAppWidgetSafely(); // Update views mFab.show(); mEmptyView.setVisibility(View.VISIBLE); mWidthSeekBar.setVisibility(View.GONE); mWidthMessageView.setVisibility(View.GONE); mHeightSeekBar.setVisibility(View.GONE); mHeightMessageView.setVisibility(View.GONE); // Update menu updateConfigureMenuItem(); updateTouchableMenuItem(); updateClearMenuItem(); return; } if (mHostView == null) { mHostView = new MyAppWidgetHostView(this); mHostView.setBackgroundResource(R.drawable.bg_appwidget_preview); updateAppWidgetTouchable(); FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL); mHostContainer.addView(mHostView, lp); } else if (!mHostViewNeedsReInflate && mHostView.getAppWidgetId() == id) return; AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(id); mAppWidgetHost.updateView(this, id, appWidget, mHostView); mHostViewNeedsReInflate = false; updateAppWidgetFrameSize(); // Update views mFab.hide(hasWindowFocus()); mEmptyView.setVisibility(View.GONE); mWidthSeekBar.setVisibility(View.VISIBLE); mWidthMessageView.setVisibility(View.VISIBLE); mHeightSeekBar.setVisibility(View.VISIBLE); mHeightMessageView.setVisibility(View.VISIBLE); // Update menu mHostView.post(new Runnable() { @Override public void run() { updateConfigureMenuItem(); updateTouchableMenuItem(); updateClearMenuItem(); } }); }
Example 19
Source File: HeadsUpBase.java From HeadsUp with GNU General Public License v2.0 | 4 votes |
/** * Adds {@link #mHolder#rootView view} to window. * * @see #detachFromWindow() */ private void attachToWindow() { if (mAttached) { // Can happen if the view is still running // exit animation. mHolder.rootView.clearAnimation(); detachFromWindow(); } else { getConfig().getTriggers().incrementLaunchCount(mHolder.context, this); } mAttached = true; boolean overlapStatusBar = mShownAtTop && getConfig().isStatusBarOverlapEnabled(); mHolder.rootView.setShownOnTop(mShownAtTop); // Define the padding Resources res = mHolder.context.getResources(); final int paddingTop = overlapStatusBar ? 0 : res.getDimensionPixelSize(R.dimen.headsup_root_padding_top); View v = mHolder.containerView; v.setPadding(v.getPaddingLeft(), paddingTop, v.getPaddingRight(), v.getPaddingBottom()); v.setTranslationY(0); // And the rotation if (!mShownAtTop) v.setBackground(res.getDrawable(R.drawable.bg_shade_flipped)); else v.setBackground(res.getDrawable(R.drawable.bg_shade)); // Add the view to the window. int layoutInScreenFlag = overlapStatusBar ? WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN : 0; WindowManager.LayoutParams lp = new WindowManager.LayoutParams( WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | layoutInScreenFlag, PixelFormat.TRANSLUCENT); lp.gravity = (mShownAtTop ? Gravity.TOP : Gravity.BOTTOM) | Gravity.CENTER_HORIZONTAL; mHolder.wm.addView(mHolder.rootView, lp); }
Example 20
Source File: BottomDrawerLayout.java From 920-text-editor-v2 with Apache License 2.0 | 4 votes |
void layoutChildren(int left, int top, int right, int bottom, boolean forceLeftGravity) { final int count = getChildCount(); final int parentLeft = getPaddingLeftWithForeground(); final int parentRight = right - left - getPaddingRightWithForeground(); final int parentTop = getPaddingTopWithForeground(); final int parentBottom = bottom - top - getPaddingBottomWithForeground(); int symbolHeight = 0; // 尽可能先找到Bottom View for (int i = count - 1; i >= 0; i--) { final View child = getChildAt(i); if (child.getVisibility() != GONE) { final LayoutParams lp = (LayoutParams) child.getLayoutParams(); final int width = child.getMeasuredWidth(); final int height = child.getMeasuredHeight(); int childLeft; int childTop; int gravity = lp.gravity; if (gravity == -1) { gravity = Gravity.NO_GRAVITY; } final int layoutDirection = ViewCompat.getLayoutDirection(this); final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection); final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: childLeft = parentLeft + (parentRight - parentLeft - width) / 2 + lp.leftMargin - lp.rightMargin; break; case Gravity.RIGHT: case Gravity.END: if (!forceLeftGravity) { childLeft = parentRight - width - lp.rightMargin; break; } case Gravity.LEFT: case Gravity.START: default: childLeft = parentLeft + lp.leftMargin; } switch (verticalGravity) { case Gravity.TOP: childTop = parentTop + lp.topMargin; break; case Gravity.CENTER_VERTICAL: childTop = parentTop + (parentBottom - parentTop - height) / 2 + lp.topMargin - lp.bottomMargin; break; case Gravity.BOTTOM: symbolHeight = ((ViewGroup)child).getChildCount() > 0 ? ((ViewGroup)child).getChildAt(0).getMeasuredHeight() : 0; float offset = mSlideOffset == 0 ? (symbolHeight == 0 ? 0.3f : symbolHeight / (float)height) : mSlideOffset; childTop = parentBottom - (int) (height * offset); // childTop = parentBottom - height - lp.bottomMargin; break; default: childTop = parentTop + lp.topMargin; } child.layout(childLeft, childTop, childLeft + width, childTop + height); } } }