List of usage examples for android.view View setPadding
public void setPadding(int left, int top, int right, int bottom)
From source file:com.mark.quick.ui.view.swipebacklayout.SwipeBackLayout.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int widthMode = MeasureSpec.getMode(widthMeasureSpec); int heightMode = MeasureSpec.getMode(heightMeasureSpec); int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); LogUtils.w("%s--HeightMeasureSpecheightModel=%s,heightSize=%s", mActivity.getClass().getSimpleName() + hashCode(), SwipeBackUIUtil.getSpecModelName(heightMode), heightSize);/* www .j av a 2s . c o m*/ //width?height??SwipeBackLayout?scrollview if (widthMode != MeasureSpec.EXACTLY) { if (isInEditMode()) { if (widthMode == MeasureSpec.AT_MOST) { widthMode = MeasureSpec.EXACTLY; } else if (widthMode == MeasureSpec.UNSPECIFIED) { widthMode = MeasureSpec.EXACTLY; widthSize = 300; } } else { throw new IllegalStateException("Width must have an exact value or MATCH_PARENT"); } } else if (heightMode == MeasureSpec.UNSPECIFIED) { //heightMode???scrollview if (isInEditMode()) { if (heightMode == MeasureSpec.UNSPECIFIED) { heightMode = MeasureSpec.AT_MOST; heightSize = 300; } } else { throw new IllegalStateException("Height must not be UNSPECIFIED"); } } int layoutHeight = 0, maxLayoutHeight = 0; switch (heightMode) { case MeasureSpec.EXACTLY: layoutHeight = maxLayoutHeight = heightSize - getPaddingTop() - getPaddingBottom(); break; case MeasureSpec.AT_MOST: maxLayoutHeight = heightSize - getPaddingTop() - getPaddingBottom(); break; } int widthAvailable = widthSize - getPaddingLeft() - getPaddingRight(); int widthRemaining = widthAvailable;//?padding int childCount = getChildCount(); if (childCount > 2) { throw new IllegalStateException(" More than two child views are not supported."); } mSlideableView = null; boolean canSlide = false; //============================================================= //SwipeShadowView?AppView /*View baseChild = getChildAt(1); LayoutParams baseChildLp = (LayoutParams) baseChild.getLayoutParams(); LogUtils.w("baseChild margin[%s,%s,%s,%s]", baseChildLp.leftMargin, baseChildLp.topMargin, baseChildLp.rightMargin, baseChildLp.bottomMargin); LogUtils.w("baseChild padding[%s,%s,%s,%s]", baseChild.getPaddingLeft(), baseChild.getPaddingTop(), baseChild.getPaddingRight(), baseChild.getPaddingBottom()); setPadding(pl, pt, pr, pb);*/ /*for (int i = 0; i < childCount; i++) { if (i == 1) continue; View otherChild = getChildAt(0); LayoutParams otherChildLp = (LayoutParams) otherChild.getLayoutParams(); otherChild.setPadding(baseChild.getPaddingLeft(), baseChild.getPaddingTop(), baseChild.getPaddingRight(), baseChild.getPaddingBottom()); otherChildLp.setMargins(baseChildLp.leftMargin, baseChildLp.topMargin, baseChildLp.rightMargin, baseChildLp.bottomMargin); }*/ View appView = getChildAt(1); if (firstMeasure) { orighPaddingTop = appView.getPaddingTop(); firstMeasure = false; } else { appView.setPadding(appView.getPaddingLeft(), orighPaddingTop, appView.getPaddingRight(), appView.getPaddingBottom()); } for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); if (child.getVisibility() == GONE) { lp.dimWhenOffset = false; continue; } int childWidthSpec; final int horizontalMargin = lp.leftMargin + lp.rightMargin; if (lp.width == LayoutParams.WRAP_CONTENT) { //?viewwarp_content?margin childWidthSpec = MeasureSpec.makeMeasureSpec(widthAvailable - horizontalMargin, MeasureSpec.AT_MOST); } else if (lp.width == LayoutParams.MATCH_PARENT) { //?viewmatch_parent?margin childWidthSpec = MeasureSpec.makeMeasureSpec(widthAvailable - horizontalMargin, MeasureSpec.EXACTLY); } else { //?viewdpdb??? childWidthSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY); } int childHeightSpec; final int verticalMargin = lp.topMargin + lp.bottomMargin; if (lp.height == LayoutParams.WRAP_CONTENT) { childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight - verticalMargin, MeasureSpec.AT_MOST); } else if (lp.height == LayoutParams.MATCH_PARENT) { childHeightSpec = MeasureSpec.makeMeasureSpec(maxLayoutHeight - verticalMargin, MeasureSpec.EXACTLY); } else { childHeightSpec = MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY); } child.measure(childWidthSpec, childHeightSpec); LogUtils.i("%s--%s child MeasureSpecheightSize=%s [pt=%s,mb=%s]", mActivity.getClass().getSimpleName() + hashCode(), i, MeasureSpec.getSize(childHeightSpec), child.getPaddingTop(), lp.bottomMargin); final int childWidth = child.getMeasuredWidth(); final int childHeight = child.getMeasuredHeight(); //?,??? if (heightMode == MeasureSpec.AT_MOST && childHeight > layoutHeight) { layoutHeight = Math.min(childHeight, maxLayoutHeight); } widthRemaining -= childWidth; canSlide |= lp.slideable = widthRemaining < 0; if (lp.slideable) { mSlideableView = child; } } //============================= // Resolve weight and make sure non-sliding panels are smaller than the full screen. final int measuredWidth = widthSize; final int measuredHeight = layoutHeight + getPaddingTop() + getPaddingBottom(); setMeasuredDimension(measuredWidth, measuredHeight); mCanSlide = canSlide; if (mDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE && !canSlide) { // Cancel scrolling in progress, it's no longer relevant. mDragHelper.abort(); } }
From source file:com.google.android.gcm.demo.ui.MainActivity.java
/** * Toggle the Logs View visibility with a nice animation. *//*from www .jav a2 s.c om*/ public void toggleLogsView(boolean showView) { final View logsView = findViewById(R.id.logs_layout); final View bodyView = findViewById(R.id.container); final FrameLayout.LayoutParams logsLayoutParams = (FrameLayout.LayoutParams) logsView.getLayoutParams(); final int startLogsY, endLogsY, startBodyY, endBodyY; if (showView) { // The logsView height set in XML is a placeholder, we need to compute at runtime // how much is 0.4 of the screen height. int height = (int) (0.4 * mDrawerLayout.getHeight()); // The LogsView is hidden being placed off-screen with a negative bottomMargin. // We need to update its height and bottomMargin to the correct runtime values. logsLayoutParams.bottomMargin = -logsLayoutParams.height; logsView.setLayoutParams(logsLayoutParams); logsLayoutParams.height = height; // Prepare the value for the Show animation. startLogsY = logsLayoutParams.bottomMargin; endLogsY = 0; startBodyY = 0; endBodyY = logsLayoutParams.height; } else { // Prepare the value for the Hide animation. startLogsY = 0; endLogsY = -logsLayoutParams.height; startBodyY = logsLayoutParams.height; endBodyY = 0; } final int deltaLogsY = endLogsY - startLogsY; final int deltaBodyY = endBodyY - startBodyY; Animation a = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { logsLayoutParams.bottomMargin = (int) (startLogsY + deltaLogsY * interpolatedTime); logsView.setLayoutParams(logsLayoutParams); bodyView.setPadding(0, 0, 0, (int) (startBodyY + deltaBodyY * interpolatedTime)); } }; a.setDuration(500); logsView.startAnimation(a); }
From source file:com.juick.android.JuickMessagesAdapter.java
private void startLoadUserPic(final JuickMessage jmsg, final MyTextView t, final ListRowRuntime lrr, ParsedMessage parsedMessage, final View userPic) { if (parsedMessage.userpicSpan != null) { lrr.pictureSize = (int) (parsedMessage.userpicSpan.getLeadingMargin(true) * 0.9); userPic.getLayoutParams().width = lrr.pictureSize; userPic.getLayoutParams().height = lrr.pictureSize; int padding = ((parsedMessage.userpicSpan.getLeadingMargin(true)) - lrr.pictureSize) / 2; userPic.setPadding(padding, padding, padding, padding); final UserpicStorage.AvatarID avatarId = getAvatarId(jmsg); lrr.avatarID = avatarId;/*from w w w .ja v a 2 s .c o m*/ lrr.userpicListener = new UserpicStorage.Listener() { @Override public void onUserpicReady(UserpicStorage.AvatarID id, int size) { lrr.removeListenerIfExists(); final Bitmap userpic = UserpicStorage.instance.getUserpic(getContext(), avatarId, lrr.pictureSize, lrr.userpicListener); if (userpic != null) { ((Activity) getContext()).runOnUiThread(new Runnable() { @Override public void run() { ListRowRuntime tag = (ListRowRuntime) t.getTag(); if (tag.jmsg.getMID() == jmsg.getMID()) { updateUserpicView(userPic, userpic); } //To change body of implemented methods use File | Settings | File Templates. } }); } } }; Bitmap bitmap = UserpicStorage.instance.getUserpic(getContext(), avatarId, lrr.pictureSize, lrr.userpicListener); if (bitmap == null) { // until it loads, we will put proper size placeholder (later re-layout minimization) bitmap = UserpicStorage.instance.getUserpic(getContext(), UserpicStorage.NO_AVATAR, lrr.pictureSize, null); } updateUserpicView(userPic, bitmap); } else { updateUserpicView(userPic, null); } }
From source file:net.etuldan.sparss.adapter.DrawerAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.item_drawer_list, parent, false); ViewHolder holder = new ViewHolder(); holder.iconView = (ImageView) convertView.findViewById(android.R.id.icon); holder.titleTxt = (TextView) convertView.findViewById(android.R.id.text1); holder.stateTxt = (TextView) convertView.findViewById(android.R.id.text2); holder.unreadTxt = (TextView) convertView.findViewById(R.id.unread_count); holder.separator = convertView.findViewById(R.id.separator); holder.separator.setBackgroundColor(ContextCompat.getColor(mContext, PrefUtils.getBoolean(PrefUtils.LIGHT_THEME, true) ? R.color.light_dividers : R.color.dark_dividers)); convertView.setTag(R.id.holder, holder); }//from ww w .j a va 2 s. c o m ViewHolder holder = (ViewHolder) convertView.getTag(R.id.holder); if (holder != null) { if (position == mSelectedItem) { holder.titleTxt.setTextColor(ContextCompat.getColor(mContext, PrefUtils.getBoolean(PrefUtils.LIGHT_THEME, true) ? R.color.light_primary_color : R.color.dark_primary_color)); } else { holder.titleTxt.setTextColor(ContextCompat.getColor(mContext, PrefUtils.getBoolean(PrefUtils.LIGHT_THEME, true) ? R.color.light_base_text : R.color.dark_base_text)); } // default init holder.iconView.setImageDrawable(null); holder.titleTxt.setText(""); holder.titleTxt.setAllCaps(false); holder.stateTxt.setVisibility(View.GONE); holder.unreadTxt.setText(""); convertView.setPadding(0, 0, 0, 0); holder.separator.setVisibility(View.GONE); if (position == 0 || position == 1) { holder.titleTxt.setText(position == 0 ? R.string.all : R.string.favorites); holder.iconView.setImageResource(position == 0 ? R.drawable.ic_statusbar_rss : R.drawable.ic_star); if (position == mSelectedItem) { holder.iconView.setColorFilter(ContextCompat.getColor(mContext, PrefUtils.getBoolean(PrefUtils.LIGHT_THEME, true) ? R.color.light_primary_color : R.color.dark_primary_color)); } else { holder.iconView.setColorFilter(ContextCompat.getColor(mContext, PrefUtils.getBoolean(PrefUtils.LIGHT_THEME, true) ? R.color.light_base_text : R.color.dark_base_text)); } int unread = position == 0 ? mAllUnreadNumber : mFavoritesNumber; if (unread != 0) { holder.unreadTxt.setText(String.valueOf(unread)); } } if (mFeedsCursor != null && mFeedsCursor.moveToPosition(position - 2)) { holder.titleTxt.setText((mFeedsCursor.isNull(POS_NAME) ? mFeedsCursor.getString(POS_URL) : mFeedsCursor.getString(POS_NAME))); if (mFeedsCursor.getInt(POS_IS_GROUP) == 1) { holder.titleTxt.setAllCaps(true); holder.separator.setVisibility(View.VISIBLE); holder.iconView.setImageResource(R.drawable.ic_folder); if (position == mSelectedItem) { holder.iconView.setColorFilter(ContextCompat.getColor(mContext, PrefUtils.getBoolean(PrefUtils.LIGHT_THEME, true) ? R.color.light_primary_color : R.color.dark_primary_color)); } else { holder.iconView.setColorFilter(ContextCompat.getColor(mContext, PrefUtils.getBoolean(PrefUtils.LIGHT_THEME, true) ? R.color.light_base_text : R.color.dark_base_text)); } } else { holder.stateTxt.setVisibility(View.VISIBLE); if (mFeedsCursor.isNull(POS_ERROR)) { long timestamp = mFeedsCursor.getLong(POS_LAST_UPDATE); // Date formatting is expensive, look at the cache String formattedDate = mFormattedDateCache.get(timestamp); if (formattedDate == null) { formattedDate = mContext.getString(R.string.update) + COLON; if (timestamp == 0) { formattedDate += mContext.getString(R.string.never); } else { formattedDate += StringUtils.getDateTimeString(timestamp); } mFormattedDateCache.put(timestamp, formattedDate); } holder.stateTxt.setText(formattedDate); } else { holder.stateTxt.setText(new StringBuilder(mContext.getString(R.string.error)).append(COLON) .append(mFeedsCursor.getString(POS_ERROR))); } final long feedId = mFeedsCursor.getLong(POS_ID); Bitmap bitmap = UiUtils.getFaviconBitmap(feedId, mFeedsCursor, POS_ICON); if (bitmap != null) { holder.iconView.setImageBitmap(bitmap); } else { holder.iconView.setImageResource(R.mipmap.ic_launcher); } int unread = mFeedsCursor.getInt(POS_UNREAD); if (unread != 0) { holder.unreadTxt.setText(String.valueOf(unread)); } } if ((mFeedsCursor.isNull(POS_NAME) ? mFeedsCursor.getString(POS_URL) : mFeedsCursor.getString(POS_NAME)).startsWith("ERROR:")) { LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.item_drawer_null, parent, false); return convertView; } } } return convertView; }
From source file:com.facebook.LikeView.java
private void updateLayout() { // Make sure the container is horizontally aligned according to specifications. LayoutParams containerViewLayoutParams = (LayoutParams) containerView.getLayoutParams(); LinearLayout.LayoutParams buttonLayoutParams = (LinearLayout.LayoutParams) likeButton.getLayoutParams(); int viewGravity = horizontalAlignment == HorizontalAlignment.LEFT ? Gravity.LEFT : horizontalAlignment == HorizontalAlignment.CENTER ? Gravity.CENTER_HORIZONTAL : Gravity.RIGHT; containerViewLayoutParams.gravity = viewGravity | Gravity.TOP; buttonLayoutParams.gravity = viewGravity; // Choose the right auxiliary view to make visible. socialSentenceView.setVisibility(GONE); likeBoxCountView.setVisibility(GONE); View auxView; if (likeViewStyle == Style.STANDARD && likeActionController != null && !Utility.isNullOrEmpty(likeActionController.getSocialSentence())) { auxView = socialSentenceView;/*from w w w .j a v a 2 s . c o m*/ } else if (likeViewStyle == Style.BOX_COUNT && likeActionController != null && !Utility.isNullOrEmpty(likeActionController.getLikeCountString())) { updateBoxCountCaretPosition(); auxView = likeBoxCountView; } else { // No more work to be done. return; } auxView.setVisibility(VISIBLE); // Now position the auxiliary view properly LinearLayout.LayoutParams auxViewLayoutParams = (LinearLayout.LayoutParams) auxView.getLayoutParams(); auxViewLayoutParams.gravity = viewGravity; containerView.setOrientation(auxiliaryViewPosition == AuxiliaryViewPosition.INLINE ? LinearLayout.HORIZONTAL : LinearLayout.VERTICAL); if (auxiliaryViewPosition == AuxiliaryViewPosition.TOP || (auxiliaryViewPosition == AuxiliaryViewPosition.INLINE && horizontalAlignment == HorizontalAlignment.RIGHT)) { // Button comes after the auxiliary view. Make sure it is at the end containerView.removeView(likeButton); containerView.addView(likeButton); } else { // In all other cases, the button comes first containerView.removeView(auxView); containerView.addView(auxView); } switch (auxiliaryViewPosition) { case TOP: auxView.setPadding(edgePadding, edgePadding, edgePadding, internalPadding); break; case BOTTOM: auxView.setPadding(edgePadding, internalPadding, edgePadding, edgePadding); break; case INLINE: if (horizontalAlignment == HorizontalAlignment.RIGHT) { auxView.setPadding(edgePadding, edgePadding, internalPadding, edgePadding); } else { auxView.setPadding(internalPadding, edgePadding, edgePadding, edgePadding); } break; } }
From source file:com.android.contacts.common.list.ViewPagerTabs.java
private void addTab(CharSequence tabTitle, final int position) { View tabView; if (mTabIcons != null && position < mTabIcons.length) { View layout = LayoutInflater.from(getContext()).inflate(R.layout.unread_count_tab, null); View iconView = layout.findViewById(R.id.icon); iconView.setBackgroundResource(mTabIcons[position]); iconView.setContentDescription(tabTitle); TextView textView = (TextView) layout.findViewById(R.id.count); if (mUnreadCounts != null && mUnreadCounts[position] > 0) { textView.setText(Integer.toString(mUnreadCounts[position])); textView.setVisibility(View.VISIBLE); iconView.setContentDescription( getResources().getQuantityString(R.plurals.tab_title_with_unread_items, mUnreadCounts[position], tabTitle.toString(), mUnreadCounts[position])); } else {// w w w. j a v a 2s . c o m textView.setVisibility(View.INVISIBLE); iconView.setContentDescription(tabTitle); } tabView = layout; } else { final TextView textView = new TextView(getContext()); textView.setText(tabTitle); textView.setBackgroundResource(R.drawable.view_pager_tab_background); // Assign various text appearance related attributes to child views. if (mTextStyle > 0) { textView.setTypeface(textView.getTypeface(), mTextStyle); } if (mTextSize > 0) { textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize); } if (mTextColor != null) { textView.setTextColor(mTextColor); } textView.setAllCaps(mTextAllCaps); textView.setGravity(Gravity.CENTER); tabView = textView; } tabView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mPager.setCurrentItem(getRtlPosition(position)); } }); tabView.setOnLongClickListener(new OnTabLongClickListener(position)); tabView.setPadding(mSidePadding, 0, mSidePadding, 0); mTabStrip.addView(tabView, position, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1)); // Default to the first child being selected if (position == 0) { mPrevSelected = 0; tabView.setSelected(true); } }
From source file:com.android.calendar.event.EditEventView.java
private void setViewStates(int mode) { // Extra canModify check just in case if (mode == Utils.MODIFY_UNINITIALIZED || !EditEventHelper.canModifyEvent(mModel)) { setWhenString();//from w w w . j av a 2 s . c o m for (View v : mViewOnlyList) { v.setVisibility(View.VISIBLE); } for (View v : mEditOnlyList) { v.setVisibility(View.GONE); } for (View v : mEditViewList) { v.setEnabled(false); v.setBackgroundDrawable(null); } mCalendarSelectorGroup.setVisibility(View.GONE); mCalendarStaticGroup.setVisibility(View.VISIBLE); mRruleButton.setEnabled(false); if (EditEventHelper.canAddReminders(mModel)) { mRemindersGroup.setVisibility(View.VISIBLE); } else { mRemindersGroup.setVisibility(View.GONE); } if (TextUtils.isEmpty(mLocationTextView.getText())) { mLocationGroup.setVisibility(View.GONE); } if (TextUtils.isEmpty(mDescriptionTextView.getText())) { mDescriptionGroup.setVisibility(View.GONE); } } else { for (View v : mViewOnlyList) { v.setVisibility(View.GONE); } for (View v : mEditOnlyList) { v.setVisibility(View.VISIBLE); } for (View v : mEditViewList) { v.setEnabled(true); if (v.getTag() != null) { v.setBackgroundDrawable((Drawable) v.getTag()); v.setPadding(mOriginalPadding[0], mOriginalPadding[1], mOriginalPadding[2], mOriginalPadding[3]); } } if (mModel.mUri == null) { mCalendarSelectorGroup.setVisibility(View.VISIBLE); mCalendarStaticGroup.setVisibility(View.GONE); } else { mCalendarSelectorGroup.setVisibility(View.GONE); mCalendarStaticGroup.setVisibility(View.VISIBLE); } if (mModel.mOriginalSyncId == null) { mRruleButton.setEnabled(true); } else { mRruleButton.setEnabled(false); mRruleButton.setBackgroundDrawable(null); } mRemindersGroup.setVisibility(View.VISIBLE); mLocationGroup.setVisibility(View.VISIBLE); mDescriptionGroup.setVisibility(View.VISIBLE); } setAllDayViewsVisibility(mAllDayCheckBox.isChecked()); }
From source file:im.vector.fragments.VectorSettingsPreferencesFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); if (null != view) { View listView = view.findViewById(android.R.id.list); if (null != listView) { listView.setPadding(0, 0, 0, 0); }//from w w w . ja va2 s . c om } return view; }