List of usage examples for android.support.v4.view MarginLayoutParamsCompat setMarginStart
public static void setMarginStart(MarginLayoutParams marginLayoutParams, int i)
From source file:com.github.andrewlord1990.snackbarbuilder.SnackbarIconBuilder.java
private LayoutParams getIconViewLayoutParams() { LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.gravity = Gravity.CENTER_VERTICAL; params.weight = 0;/* w w w. j av a2 s. c om*/ MarginLayoutParamsCompat.setMarginStart(params, iconMarginStartPixels); MarginLayoutParamsCompat.setMarginEnd(params, iconMarginEndPixels); return params; }
From source file:com.google.android.apps.flexbox.FlexItem.java
public FlexboxLayout.LayoutParams toLayoutParams(Context context) { FlexboxLayout.LayoutParams lp = new FlexboxLayout.LayoutParams(Util.dpToPixel(context, width), Util.dpToPixel(context, height)); lp.order = order;/*ww w.j a v a 2 s .co m*/ lp.flexGrow = flexGrow; lp.flexShrink = flexShrink; lp.alignSelf = alignSelf; lp.flexBasisPercent = flexBasisPercent; lp.topMargin = topMargin; MarginLayoutParamsCompat.setMarginStart(lp, startMargin); MarginLayoutParamsCompat.setMarginEnd(lp, endMargin); lp.bottomMargin = bottomMargin; lp.minWidth = Util.dpToPixel(context, minWidth); lp.minHeight = Util.dpToPixel(context, minHeight); lp.maxWidth = Util.dpToPixel(context, maxWidth); lp.maxHeight = Util.dpToPixel(context, maxHeight); lp.wrapBefore = wrapBefore; return lp; }
From source file:com.murrayc.galaxyzoo.app.QuestionHelpFragment.java
private void addRowForAnswer(final Context context, final TableLayout tableLayout, final DecisionTree.Question question, final DecisionTree.BaseButton answer) { final TableRow row = new TableRow(context); final TableLayout.LayoutParams params = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT); params.setMargins(0, UiUtils.getPxForDpResource(context, R.dimen.standard_large_margin), 0, 0); tableLayout.addView(row, params);//from w w w .j a v a 2s. co m final LinearLayout layoutVertical = new LinearLayout(context); layoutVertical.setOrientation(LinearLayout.VERTICAL); final TextView textViewAnswer = new AppCompatTextView(context); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { textViewAnswer.setTextAppearance(R.style.TextAppearance_AppCompat_Subhead); } else { //noinspection deprecation textViewAnswer.setTextAppearance(context, R.style.TextAppearance_AppCompat_Subhead); } textViewAnswer.setText(answer.getText()); layoutVertical.addView(textViewAnswer, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); final LinearLayout layoutHorizontal = new LinearLayout(context); layoutHorizontal.setOrientation(LinearLayout.HORIZONTAL); final LinearLayout.LayoutParams paramsHorizontal = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); paramsHorizontal.setMargins(0, UiUtils.getPxForDpResource(context, R.dimen.standard_margin), 0, 0); layoutVertical.addView(layoutHorizontal, paramsHorizontal); final BitmapDrawable icon = getIcon(context, answer); final ImageView imageIcon = new ImageView(context); imageIcon.setImageDrawable(icon); layoutHorizontal.addView(imageIcon); final LinearLayout.LayoutParams paramsImage = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); // TODO: Use a custom FlowTable class to avoid items going off the right edge of the screen // when there are too many. final Singleton singleton = getSingleton(); for (int i = 0; i < answer.getExamplesCount(); i++) { final String iconName = answer.getExampleIconName(question.getId(), i); final BitmapDrawable iconExample = singleton.getIconDrawable(context, iconName); final ImageButton imageExample = new ImageButton(context); //Remove the space between the image and the outside of the button: imageExample.setPadding(0, 0, 0, 0); imageExample.setImageDrawable(iconExample); //Needed to make the image expand as a transition into the SubjectViewerActivity, //which uses the same name in fragment_subject.xml ViewCompat.setTransitionName(imageExample, getString(R.string.transition_subject_image)); //This requires API level 17: paramsImage.setMarginStart(getPxForDp(activity, MARGIN_MEDIUM_DP)); //imageExample.setLayoutParams(paramsImage); MarginLayoutParamsCompat.setMarginStart(paramsImage, UiUtils.getPxForDpResource(context, R.dimen.standard_large_margin)); final int answerIndex = i; imageExample.setOnClickListener(new View.OnClickListener() { public void onClick(final View v) { // Perform action on click onExampleImageClicked(v, answer, answerIndex); } }); layoutHorizontal.addView(imageExample, paramsImage); } row.addView(layoutVertical, new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT)); }
From source file:com.justplay1.shoppist.features.search.widget.FloatingSearchView.java
private void applyXmlAttributes(AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) { final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.FloatingSearchView, defStyleAttr, defStyleRes);//from ww w .j ava 2 s . com // Search bar width View suggestionsContainer = findViewById(R.id.fsv_suggestions_container); int searchBarWidth = a.getDimensionPixelSize(R.styleable.FloatingSearchView_fsv_searchBarWidth, searchContainer.getLayoutParams().width); searchContainer.getLayoutParams().width = searchBarWidth; suggestionsContainer.getLayoutParams().width = searchBarWidth; // Divider ViewUtils.setBackground(divider, a.getDrawable(R.styleable.FloatingSearchView_android_divider)); int dividerHeight = a.getDimensionPixelSize(R.styleable.FloatingSearchView_android_dividerHeight, -1); MarginLayoutParams dividerLP = (MarginLayoutParams) divider.getLayoutParams(); if (divider.getBackground() != null && dividerHeight != -1) dividerLP.height = dividerHeight; float maxShadowSize = searchBackground.getMaxShadowSize(); float cornerRadius = searchBackground.getCornerRadius(); int horizontalPadding = (int) (RoundRectDrawableWithShadow.calculateHorizontalPadding(maxShadowSize, cornerRadius, false) + .5f); dividerLP.setMargins(horizontalPadding, dividerLP.topMargin, horizontalPadding, dividerLP.bottomMargin); divider.setLayoutParams(dividerLP); // Content inset MarginLayoutParams searchParams = (MarginLayoutParams) searchInput.getLayoutParams(); int contentInsetStart = a.getDimensionPixelSize(R.styleable.FloatingSearchView_contentInsetStart, MarginLayoutParamsCompat.getMarginStart(searchParams)); int contentInsetEnd = a.getDimensionPixelSize(R.styleable.FloatingSearchView_contentInsetEnd, MarginLayoutParamsCompat.getMarginEnd(searchParams)); MarginLayoutParamsCompat.setMarginStart(searchParams, contentInsetStart); MarginLayoutParamsCompat.setMarginEnd(searchParams, contentInsetEnd); // anything else setLogo(a.getDrawable(R.styleable.FloatingSearchView_logo)); setContentBackgroundColor( a.getColor(R.styleable.FloatingSearchView_fsv_contentBackgroundColor, DEFAULT_CONTENT_COLOR)); setRadius(a.getDimensionPixelSize(R.styleable.FloatingSearchView_fsv_cornerRadius, ViewUtils.dpToPx(DEFAULT_RADIUS))); inflateMenu(a.getResourceId(R.styleable.FloatingSearchView_fsv_menu, 0)); setPopupTheme(a.getResourceId(R.styleable.FloatingSearchView_popupTheme, 0)); setHint(a.getString(R.styleable.FloatingSearchView_android_hint)); setIcon(a.getDrawable(R.styleable.FloatingSearchView_fsv_icon)); a.recycle(); }