Java Code Examples for android.support.v4.view.ViewCompat#setPaddingRelative()
The following examples show how to use
android.support.v4.view.ViewCompat#setPaddingRelative() .
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: Utils.java From ThreePhasesBottomSheet with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * sets a single padding on a view, without changing the rest of the padding values of the view */ public static void setPaddingOrRelativePadding(View v, ViewPadding paddingType, int paddingValueToSetInPixels) { switch (paddingType) { case BOTTOM: ViewCompat.setPaddingRelative(v, ViewCompat.getPaddingStart(v), v.getPaddingTop(), ViewCompat.getPaddingEnd(v), paddingValueToSetInPixels); break; case END_OR_RIGHT: ViewCompat.setPaddingRelative(v, ViewCompat.getPaddingStart(v), v.getPaddingTop(), paddingValueToSetInPixels, v.getPaddingBottom()); break; case START_OR_LEFT: ViewCompat.setPaddingRelative(v, paddingValueToSetInPixels, v.getPaddingTop(), ViewCompat.getPaddingEnd(v), v.getPaddingBottom()); break; case TOP: ViewCompat.setPaddingRelative(v, ViewCompat.getPaddingStart(v), paddingValueToSetInPixels, ViewCompat.getPaddingEnd(v), v.getPaddingBottom()); break; } }
Example 2
Source File: DachshundTabLayout.java From Dachshund-Tab-Layout with MIT License | 6 votes |
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); if (mCenterAlign) { View firstTab = ((ViewGroup) getChildAt(0)).getChildAt(0); View lastTab = ((ViewGroup) getChildAt(0)).getChildAt(((ViewGroup) getChildAt(0)).getChildCount() - 1); ViewCompat.setPaddingRelative(getChildAt(0), (getWidth() / 2) - (firstTab.getWidth() / 2), 0, (getWidth() / 2) - (lastTab.getWidth() / 2), 0); } if (mAnimatedIndicator == null) { setupAnimatedIndicator(); } onPageScrolled(mTempPosition, mTempPositionOffset, mTempPositionOffsetPixels); }
Example 3
Source File: AppDetailsRecyclerViewAdapter.java From fdroidclient with GNU General Public License v3.0 | 6 votes |
VersionViewHolder(View view) { super(view); version = (TextView) view.findViewById(R.id.version); statusInstalled = (TextView) view.findViewById(R.id.status_installed); statusSuggested = (TextView) view.findViewById(R.id.status_suggested); statusIncompatible = (TextView) view.findViewById(R.id.status_incompatible); versionCode = view.findViewById(R.id.versionCode); added = (TextView) view.findViewById(R.id.added); expandArrow = (ImageView) view.findViewById(R.id.expand_arrow); expandedLayout = (View) view.findViewById(R.id.expanded_layout); repository = (TextView) view.findViewById(R.id.repository); size = (TextView) view.findViewById(R.id.size); api = (TextView) view.findViewById(R.id.api); buttonInstallUpgrade = (Button) view.findViewById(R.id.button_install_upgrade); buttonDowngrade = (Button) view.findViewById(R.id.button_downgrade); busyIndicator = (View) view.findViewById(R.id.busy_indicator); incompatibleReasons = (TextView) view.findViewById(R.id.incompatible_reasons); targetArch = (TextView) view.findViewById(R.id.target_arch); int margin = context.getResources().getDimensionPixelSize(R.dimen.layout_horizontal_margin); int padding = context.getResources().getDimensionPixelSize(R.dimen.details_activity_padding); ViewCompat.setPaddingRelative(view, margin + padding + ViewCompat.getPaddingStart(view), view.getPaddingTop(), margin + ViewCompat.getPaddingEnd(view), view.getPaddingBottom()); }
Example 4
Source File: SmartTabLayout.java From imsdk-android with MIT License | 5 votes |
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); if (tabStrip.isIndicatorAlwaysInCenter() && tabStrip.getChildCount() > 0) { View firstTab = tabStrip.getChildAt(0); View lastTab = tabStrip.getChildAt(getChildCount() - 1); int start = (w - Utils.getMeasuredWidth(firstTab)) / 2 - Utils.getMarginStart(firstTab); int end = (w - Utils.getMeasuredWidth(lastTab)) / 2 - Utils.getMarginEnd(lastTab); tabStrip.setMinimumWidth(tabStrip.getMeasuredWidth()); ViewCompat.setPaddingRelative(this, start, getPaddingTop(), end, getPaddingBottom()); setClipToPadding(false); } }
Example 5
Source File: TabLayout.java From attendee-checkin with Apache License 2.0 | 5 votes |
public TabView(Context context, Tab tab) { super(context); mTab = tab; if (mTabBackgroundResId != 0) { setBackgroundDrawable(TintManager.getDrawable(context, mTabBackgroundResId)); } ViewCompat.setPaddingRelative(this, mTabPaddingStart, mTabPaddingTop, mTabPaddingEnd, mTabPaddingBottom); setGravity(Gravity.CENTER); update(); }
Example 6
Source File: Snackbar.java From Nimingban with Apache License 2.0 | 5 votes |
private static void updateTopBottomPadding(View view, int topPadding, int bottomPadding) { if (ViewCompat.isPaddingRelative(view)) { ViewCompat.setPaddingRelative(view, ViewCompat.getPaddingStart(view), topPadding, ViewCompat.getPaddingEnd(view), bottomPadding); } else { view.setPadding(view.getPaddingLeft(), topPadding, view.getPaddingRight(), bottomPadding); } }
Example 7
Source File: SweetSnackbar.java From SweetTips with Apache License 2.0 | 5 votes |
private static void updateTopBottomPadding(View view, int topPadding, int bottomPadding) { if (ViewCompat.isPaddingRelative(view)) { ViewCompat.setPaddingRelative(view, ViewCompat.getPaddingStart(view), topPadding, ViewCompat.getPaddingEnd(view), bottomPadding); } else { view.setPadding(view.getPaddingLeft(), topPadding, view.getPaddingRight(), bottomPadding); } }
Example 8
Source File: SmartTabLayout.java From KUtils-master with Apache License 2.0 | 5 votes |
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); if (tabStrip.isIndicatorAlwaysInCenter() && tabStrip.getChildCount() > 0) { View firstTab = tabStrip.getChildAt(0); View lastTab = tabStrip.getChildAt(tabStrip.getChildCount() - 1); int start = (w - Utils.getMeasuredWidth(firstTab)) / 2 - Utils.getMarginStart(firstTab); int end = (w - Utils.getMeasuredWidth(lastTab)) / 2 - Utils.getMarginEnd(lastTab); tabStrip.setMinimumWidth(tabStrip.getMeasuredWidth()); ViewCompat.setPaddingRelative(this, start, getPaddingTop(), end, getPaddingBottom()); setClipToPadding(false); } }
Example 9
Source File: SweetSnackbar.java From SweetTips with Apache License 2.0 | 5 votes |
private static void updateTopBottomPadding(View view, int topPadding, int bottomPadding) { if (ViewCompat.isPaddingRelative(view)) { ViewCompat.setPaddingRelative(view, ViewCompat.getPaddingStart(view), topPadding, ViewCompat.getPaddingEnd(view), bottomPadding); } else { view.setPadding(view.getPaddingLeft(), topPadding, view.getPaddingRight(), bottomPadding); } }
Example 10
Source File: SmartTabLayout.java From KUtils with Apache License 2.0 | 5 votes |
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); if (tabStrip.isIndicatorAlwaysInCenter() && tabStrip.getChildCount() > 0) { View firstTab = tabStrip.getChildAt(0); View lastTab = tabStrip.getChildAt(tabStrip.getChildCount() - 1); int start = (w - Utils.getMeasuredWidth(firstTab)) / 2 - Utils.getMarginStart(firstTab); int end = (w - Utils.getMeasuredWidth(lastTab)) / 2 - Utils.getMarginEnd(lastTab); tabStrip.setMinimumWidth(tabStrip.getMeasuredWidth()); ViewCompat.setPaddingRelative(this, start, getPaddingTop(), end, getPaddingBottom()); setClipToPadding(false); } }
Example 11
Source File: CircularTabLayoutAdapter.java From CircularViewPager with MIT License | 5 votes |
public TabView(Context context, int background, int[] margins, int[] paddings, int tabMinWidth, int tabMaxWidth, int tabTextSize, int tabTextAppearance, ColorStateList tabTextColors) { super(context); if (background != 0) { setBackgroundDrawable(getDrawable(context, background)); } ViewCompat.setPaddingRelative(this, paddings[0], paddings[1], paddings[2], paddings[3]); mTabMinWidth = tabMinWidth; mTabMaxWidth = tabMaxWidth; mTabTextSize = tabTextSize; mTabTextAppearance = tabTextAppearance; mTabTextColors = tabTextColors; MarginLayoutParams marginLayoutParams = new MarginLayoutParams(MarginLayoutParams.WRAP_CONTENT, MarginLayoutParams.WRAP_CONTENT); marginLayoutParams.leftMargin = margins[0]; marginLayoutParams.topMargin = margins[1]; marginLayoutParams.rightMargin = margins[2]; marginLayoutParams.bottomMargin = margins[3]; setLayoutParams(marginLayoutParams); setGravity(Gravity.CENTER); }
Example 12
Source File: CircularTabLayoutAdapter.java From CircularViewPager with MIT License | 5 votes |
public TabView(Context context, int background, int[] margins, int[] paddings, int tabMinWidth, int tabMaxWidth, int tabTextSize, int tabTextAppearance, ColorStateList tabTextColors) { super(context); if (background != 0) { setBackgroundDrawable(getDrawable(context, background)); } ViewCompat.setPaddingRelative(this, paddings[0], paddings[1], paddings[2], paddings[3]); mTabMinWidth = tabMinWidth; mTabMaxWidth = tabMaxWidth; mTabTextSize = tabTextSize; mTabTextAppearance = tabTextAppearance; mTabTextColors = tabTextColors; MarginLayoutParams marginLayoutParams = new MarginLayoutParams(MarginLayoutParams.WRAP_CONTENT, MarginLayoutParams.WRAP_CONTENT); marginLayoutParams.leftMargin = margins[0]; marginLayoutParams.topMargin = margins[1]; marginLayoutParams.rightMargin = margins[2]; marginLayoutParams.bottomMargin = margins[3]; setLayoutParams(marginLayoutParams); setGravity(Gravity.CENTER); }
Example 13
Source File: HelperTextInputLayout.java From trust-wallet-android-source with GNU General Public License v3.0 | 5 votes |
public void setHelperTextEnabled(boolean _enabled) { if (mHelperTextEnabled == _enabled) return; if (_enabled && mErrorEnabled) { setErrorEnabled(false); } if (this.mHelperTextEnabled != _enabled) { if (_enabled) { this.mHelperView = new TextView(this.getContext()); this.mHelperView.setTextAppearance(this.getContext(), this.mHelperTextAppearance); if (mHelperTextColor != null){ this.mHelperView.setTextColor(mHelperTextColor); } this.mHelperView.setVisibility(INVISIBLE); this.addView(this.mHelperView); if (this.mHelperView != null) { ViewCompat.setPaddingRelative( this.mHelperView, ViewCompat.getPaddingStart(getEditText()), 0, ViewCompat.getPaddingEnd(getEditText()), getEditText().getPaddingBottom()); } } else { this.removeView(this.mHelperView); this.mHelperView = null; } this.mHelperTextEnabled = _enabled; } }
Example 14
Source File: TagView.java From Collection-Android with MIT License | 5 votes |
/** * TagView * 动态创建TextView * @return */ private TextView createNewFlexItemTextView(String str, final int pos) { TextView textView = new TextView(mContext); textView.setGravity(Gravity.CENTER); textView.setText(str); textView.setTextSize(tagViewBuilder.getTextSize()); textView.setTextColor(ColorUtils.createColorStateList(tagViewBuilder.getTextSelectColor(),tagViewBuilder.getTextSelectColor(),tagViewBuilder.getTextColor())); textView.setTag(pos); textView.setBackgroundResource(tagViewBuilder.getBackgroudRes()); textView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { int position= (int) v.getTag(); onTagViewPressListener.onPress(v,tagViewBuilder.getTitles()[position],position); } }); float padding = DisplayUtils.dip2px(mContext, tagViewBuilder.getPaddingTopAndBottom()); float paddingLeftAndRight = DisplayUtils.dip2px(mContext, tagViewBuilder.getPaddingLeftAndRight()); ViewCompat.setPaddingRelative( textView, (int)paddingLeftAndRight, (int)padding, (int)paddingLeftAndRight, (int)padding ); LayoutParams layoutParams = new LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT ); float margin = DisplayUtils.dip2px(mContext, tagViewBuilder.getMarginLeftAndRight()); float marginTopAndBottom = DisplayUtils.dip2px(mContext, tagViewBuilder.getMarginTopAndBottom()); layoutParams.setMargins((int)margin, (int)marginTopAndBottom, (int)margin, (int)marginTopAndBottom); layoutParams.setMargins(10,10,10,10); textView.setLayoutParams(layoutParams); return textView; }
Example 15
Source File: ViewUtils.java From android-topeka with Apache License 2.0 | 4 votes |
@Override public void setValue(TextView view, int paddingStart) { ViewCompat.setPaddingRelative(view, paddingStart, view.getPaddingTop(), ViewCompat.getPaddingEnd(view), view.getPaddingBottom()); }
Example 16
Source File: ViewUtils.java From android-topeka with Apache License 2.0 | 4 votes |
public static void setPaddingStart(TextView target, int paddingStart) { ViewCompat.setPaddingRelative(target, paddingStart, target.getPaddingTop(), ViewCompat.getPaddingEnd(target), target.getPaddingBottom()); }
Example 17
Source File: ViewUtils.java From CoolSignIn with Apache License 2.0 | 4 votes |
@Override public void setValue(TextView view, int paddingStart) { ViewCompat.setPaddingRelative(view, paddingStart, view.getPaddingTop(), ViewCompat.getPaddingEnd(view), view.getPaddingBottom()); }
Example 18
Source File: RecyclerTabLayout.java From RecyclerTabLayout with Apache License 2.0 | 4 votes |
@SuppressWarnings("deprecation") @Override public DefaultAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { TabTextView tabTextView = new TabTextView(parent.getContext()); if (mTabSelectedTextColorSet) { tabTextView.setTextColor(tabTextView.createColorStateList( tabTextView.getCurrentTextColor(), mTabSelectedTextColor)); } ViewCompat.setPaddingRelative(tabTextView, mTabPaddingStart, mTabPaddingTop, mTabPaddingEnd, mTabPaddingBottom); tabTextView.setTextAppearance(parent.getContext(), mTabTextAppearance); tabTextView.setGravity(Gravity.CENTER); tabTextView.setMaxLines(MAX_TAB_TEXT_LINES); tabTextView.setEllipsize(TextUtils.TruncateAt.END); if (mTabOnScreenLimit > 0) { int width = parent.getMeasuredWidth() / mTabOnScreenLimit; tabTextView.setMaxWidth(width); tabTextView.setMinWidth(width); } else { if (mTabMaxWidth > 0) { tabTextView.setMaxWidth(mTabMaxWidth); } tabTextView.setMinWidth(mTabMinWidth); } tabTextView.setTextAppearance(tabTextView.getContext(), mTabTextAppearance); if (mTabSelectedTextColorSet) { tabTextView.setTextColor(tabTextView.createColorStateList( tabTextView.getCurrentTextColor(), mTabSelectedTextColor)); } if (mTabBackgroundResId != 0) { tabTextView.setBackgroundDrawable( AppCompatResources.getDrawable(tabTextView.getContext(), mTabBackgroundResId)); } tabTextView.setLayoutParams(createLayoutParamsForTabs()); return new ViewHolder(tabTextView); }
Example 19
Source File: ViewUtils.java From CoolSignIn with Apache License 2.0 | 4 votes |
public static void setPaddingStart(TextView target, int paddingStart) { ViewCompat.setPaddingRelative(target, paddingStart, target.getPaddingTop(), ViewCompat.getPaddingEnd(target), target.getPaddingBottom()); }
Example 20
Source File: PostListActivity.java From quill with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (! AccountManager.hasActiveBlog()) { Intent intent = new Intent(this, LoginActivity.class); startActivity(intent); finish(); return; } if (! AccountManager.getActiveBlog().isLoggedIn()) { // is it safe to infer that an active blog which is not logged in must mean the // password has changed or Ghost Auth code is expired? credentialsExpired(); } setLayout(R.layout.activity_post_list); setSupportActionBar(mToolbar); if (BuildConfig.DEBUG) { SpectreApplication.getInstance().addDebugDrawer(this); } // get rid of the default action bar confetti //noinspection ConstantConditions getSupportActionBar().setDisplayOptions(0); // constants for animation TypedValue typedColorValue = new TypedValue(); getTheme().resolveAttribute(R.attr.colorAccent, typedColorValue, true); mColorAccent = typedColorValue.data; getTheme().resolveAttribute(R.attr.colorPrimary, typedColorValue, true); mColorPrimary = typedColorValue.data; // initialize post list UI final String activeBlogUrl = AccountManager.getActiveBlogUrl(); mPostAdapter = new PostAdapter(this, mPosts, activeBlogUrl, getPicasso(), v -> { int pos = mPostList.getChildLayoutPosition(v); if (pos == RecyclerView.NO_POSITION) return; Post post = (Post) mPostAdapter.getItem(pos); if (post.isMarkedForDeletion()) { Snackbar.make(mPostList, R.string.status_marked_for_deletion_open_error, Snackbar.LENGTH_SHORT).show(); return; } Intent intent = new Intent(PostListActivity.this, PostViewActivity.class); intent.putExtra(BundleKeys.POST, post); intent.putExtra(BundleKeys.START_EDITING, false); Bundle activityOptions = ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getWidth(), v.getHeight()).toBundle(); startActivityForResult(intent, REQUEST_CODE_VIEW_POST, activityOptions); }); mPostList.setAdapter(mPostAdapter); mPostList.setLayoutManager(new StaggeredGridLayoutManager( getResources().getInteger(R.integer.post_grid_num_columns), StaggeredGridLayoutManager.VERTICAL)); mPostList.setItemAnimator(new DefaultItemAnimator()); int hSpace = getResources().getDimensionPixelOffset(R.dimen.card_grid_hspace); int vSpace = getResources().getDimensionPixelOffset(R.dimen.card_grid_vspace); mPostList.addItemDecoration(new SpaceItemDecoration(hSpace, vSpace)); // use a fixed-width grid on large screens int screenWidth = DeviceUtils.getScreenWidth(this); int maxContainerWidth = getResources().getDimensionPixelSize(R.dimen.post_grid_max_width); if (screenWidth > maxContainerWidth) { int containerPadding = (screenWidth - maxContainerWidth) / 2; ViewCompat.setPaddingRelative(mToolbar, ViewCompat.getPaddingStart(mToolbar) + containerPadding, mToolbar.getPaddingTop(), ViewCompat.getPaddingEnd(mToolbar) + containerPadding, mToolbar.getPaddingBottom()); ViewCompat.setPaddingRelative(mPostList, ViewCompat.getPaddingStart(mPostList) + containerPadding, mPostList.getPaddingTop(), ViewCompat.getPaddingEnd(mPostList) + containerPadding, mPostList.getPaddingBottom()); } final Drawable appbarShadowDrawable; appbarShadowDrawable = ContextCompat.getDrawable(this, R.drawable.appbar_shadow); mPostListContainer.setForeground(null); // hide the shadow initially mPostList.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); int scrollY = mPostList.computeVerticalScrollOffset(); mAppBarBg.setTranslationY(-scrollY); mPostListContainer.setForeground(scrollY <= 0 ? null : appbarShadowDrawable); } }); mRefreshDataRunnable = () -> refreshData(false); mRefreshTimeoutRunnable = this::refreshTimedOut; mSwipeRefreshLayout.setColorSchemeColors(mColorAccent, mColorPrimary); mSwipeRefreshLayout.setOnRefreshListener(() -> refreshData(false)); }