本文整理汇总了Java中com.google.android.flexbox.FlexboxLayout.LayoutParams方法的典型用法代码示例。如果您正苦于以下问题:Java FlexboxLayout.LayoutParams方法的具体用法?Java FlexboxLayout.LayoutParams怎么用?Java FlexboxLayout.LayoutParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.flexbox.FlexboxLayout
的用法示例。
在下文中一共展示了FlexboxLayout.LayoutParams方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fromFlexView
import com.google.android.flexbox.FlexboxLayout; //导入方法依赖的package包/类
public static FlexItem fromFlexView(View view, int index) {
FlexboxLayout.LayoutParams lp = (FlexboxLayout.LayoutParams) view.getLayoutParams();
FlexItem flexItem = new FlexItem();
flexItem.index = index;
flexItem.order = lp.order;
flexItem.flexGrow = lp.flexGrow;
flexItem.flexShrink = lp.flexShrink;
flexItem.alignSelf = lp.alignSelf;
flexItem.flexBasisPercent = lp.flexBasisPercent;
flexItem.width = Util.pixelToDp(view.getContext(), lp.width);
flexItem.height = Util.pixelToDp(view.getContext(), lp.height);
flexItem.topMargin = lp.topMargin;
flexItem.startMargin = MarginLayoutParamsCompat.getMarginStart(lp);
flexItem.endMargin = MarginLayoutParamsCompat.getMarginEnd(lp);
flexItem.bottomMargin = lp.bottomMargin;
flexItem.paddingTop = view.getPaddingTop();
flexItem.paddingStart = ViewCompat.getPaddingStart(view);
flexItem.paddingEnd = ViewCompat.getPaddingEnd(view);
flexItem.paddingBottom = view.getPaddingBottom();
return flexItem;
}
示例2: addItemTrainCategories
import com.google.android.flexbox.FlexboxLayout; //导入方法依赖的package包/类
public ItemBuilder addItemTrainCategories(Context context) {
view = inflater.inflate(R.layout.item_element_categories_checkboxes, parent, false);
TextView tv = (TextView) view.findViewById(R.id.tv_title);
TextView tv2 = (TextView) view.findViewById(R.id.tv_subtitle);
FlexboxLayout fblCategories = (FlexboxLayout) view.findViewById(R.id.fbl_categories);
tv.setText("Categorie di treni incluse nella ricerca");
tv2.setText(SettingsPreferences.getCategoriesAsString(context, " / "));
for (ENUM_CATEGORIES cat : ENUM_CATEGORIES.values()) {
CheckBox cbCat = new CheckBox(context);
FlexboxLayout.LayoutParams params = new FlexboxLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.flexBasisPercent = 0.5f;
cbCat.setLayoutParams(params);
cbCat.setText(cat.getAlias());
cbCat.setChecked(SettingsPreferences.isCategoryEnabled(context, cat));
cbCat.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked || (!isChecked && SettingsPreferences.isPossibleToDisableCheckbox(context))) {
SettingsPreferences.setCategory(context, cat.name(), isChecked);
tv2.setText(SettingsPreferences.getCategoriesAsString(context, " / "));
} else {
cbCat.setChecked(true);
}
});
fblCategories.addView(cbCat);
}
return this;
}
示例3: createLayoutParams
import com.google.android.flexbox.FlexboxLayout; //导入方法依赖的package包/类
public static void createLayoutParams(LayoutParamsCreator creator, ViewGroup.LayoutParams
outParams) {
outParams.height = creator.height;
outParams.width = creator.width;
if (outParams instanceof HNDivLayout.HNDivLayoutParams) {
((HNDivLayout.HNDivLayoutParams) outParams).setMargins(creator.marginLeft, creator
.marginTop, creator.marginRight, creator.marginBottom);
((HNDivLayout.HNDivLayoutParams) outParams).positionMode = creator.positionMode;
((HNDivLayout.HNDivLayoutParams) outParams).left = creator.left;
((HNDivLayout.HNDivLayoutParams) outParams).top = creator.top;
((HNDivLayout.HNDivLayoutParams) outParams).bottom = creator.bottom;
((HNDivLayout.HNDivLayoutParams) outParams).right = creator.right;
} else if (outParams instanceof FlexboxLayout.LayoutParams) {
//TODO complete
} else if (outParams instanceof ViewGroup.MarginLayoutParams) {
((ViewGroup.MarginLayoutParams) outParams).setMargins(creator.marginLeft, creator
.marginTop, creator.marginRight, creator.marginBottom);
} else {
throw new IllegalArgumentException("can't create related layoutParams, unknown " +
"layoutParams type " + outParams.toString());
}
}
示例4: testLoadFromLayoutXml
import com.google.android.flexbox.FlexboxLayout; //导入方法依赖的package包/类
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testLoadFromLayoutXml() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
mActivityRule.runOnUiThread(new Runnable() {
@Override
public void run() {
activity.setContentView(R.layout.activity_simple);
}
});
FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
assertNotNull(flexboxLayout);
assertThat(flexboxLayout.getFlexDirection(), is(FlexboxLayout.FLEX_DIRECTION_ROW_REVERSE));
assertThat(flexboxLayout.getJustifyContent(), is(FlexboxLayout.JUSTIFY_CONTENT_CENTER));
assertThat(flexboxLayout.getAlignContent(), is(FlexboxLayout.ALIGN_CONTENT_CENTER));
assertThat(flexboxLayout.getAlignItems(), is(FlexboxLayout.ALIGN_ITEMS_CENTER));
assertThat(flexboxLayout.getChildCount(), is(1));
View child = flexboxLayout.getChildAt(0);
FlexboxLayout.LayoutParams lp = (FlexboxLayout.LayoutParams) child.getLayoutParams();
assertThat(lp.order, is(2));
assertThat(lp.flexGrow, is(1f));
assertThat(lp.alignSelf, is(FlexboxLayout.LayoutParams.ALIGN_SELF_STRETCH));
}
示例5: onDataChild
import com.google.android.flexbox.FlexboxLayout; //导入方法依赖的package包/类
public void onDataChild(List<ReadChildTypeBean> datas) {
View mHeaderView = inflate(getContext(), R.layout.recycler_header_read, null);
FlexboxLayout flexboxLayout = findById(mHeaderView, R.id.flexboxLayout);
if (flexboxLayout.getRootView() == null)
return;
flexboxLayout.removeAllViews();
for (ReadChildTypeBean data : datas) {
ImageView imageView = new ImageView(getContext());
FlexboxLayout.LayoutParams layoutParams = new FlexboxLayout.LayoutParams(DensityUtils.dip2px(getContext(), 30), DensityUtils.dip2px(getContext(), 30));
imageView.setLayoutParams(layoutParams);
imageView.setOnClickListener(v -> ReadMoreActivity.start(getContext(),data.getUrl(),data.getTitle(),data.getImg()));
flexboxLayout.addView(imageView);
int size = DensityUtils.dip2px(getContext(), 10);
FlexboxLayout.LayoutParams layoutParam = (FlexboxLayout.LayoutParams) imageView
.getLayoutParams();
layoutParam.setMargins(size, size, size, 0);
imageView.setLayoutParams(layoutParam);
GlideImageLoader.loadAdapterCircle(getContext(), data.getImg(), imageView);
}
RecyclerViewUtils.setHeaderView(recyclerView, mHeaderView);
}
示例6: initChildViews
import com.google.android.flexbox.FlexboxLayout; //导入方法依赖的package包/类
private void initChildViews() {
final FlexboxLayout sourceLayout = (FlexboxLayout) findViewById(R.id.remaining_phrases);
final FlexboxLayout targetLayout = (FlexboxLayout) findViewById(R.id.user_inputted_phrases);
final FlexboxLayout.LayoutParams phraseParams = generateLayoutParams();
sourceLayout.removeAllViews();
targetLayout.removeAllViews();
for (final String phrase : this.remainingInputBackupPhrase) {
final DraggableShadowTextView userInputtedTextView = generateTargetTextView();
final DraggableShadowTextView remainingTextView = generateSourceTextView(phrase);
sourceLayout.addView(remainingTextView, phraseParams);
targetLayout.addView(userInputtedTextView, phraseParams);
}
sourceLayout.requestLayout();
targetLayout.requestLayout();
}
示例7: setFilters
import com.google.android.flexbox.FlexboxLayout; //导入方法依赖的package包/类
public void setFilters(@Nullable List<SearchFilter> filters) {
mSearchFilters = filters;
mFlexboxLayout.removeAllViews();
if (filters == null) {
mSearchFiltersStates = null;
mFlexboxLayout.setVisibility(View.GONE);
} else {
mSearchFiltersStates = new ArrayList<>();
for (SearchFilter filter : filters) {
AppCompatCheckBox checkBox = new AppCompatCheckBox(mContext);
checkBox.setText(filter.getTitle());
checkBox.setTextSize(12);
checkBox.setTextColor(mTextColor);
checkBox.setChecked(filter.isChecked());
FlexboxLayout.LayoutParams lp = new FlexboxLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(getResources().getDimensionPixelSize(R.dimen.search_filter_margin_start), getResources().getDimensionPixelSize(R.dimen.search_filter_margin_top), getResources().getDimensionPixelSize(R.dimen.search_filter_margin_top), getResources().getDimensionPixelSize(R.dimen.search_filter_margin_top));
checkBox.setLayoutParams(lp);
checkBox.setTag(filter.getTagId());
mFlexboxLayout.addView(checkBox);
mSearchFiltersStates.add(filter.isChecked());
}
}
}
示例8: createChild
import com.google.android.flexbox.FlexboxLayout; //导入方法依赖的package包/类
public void createChild() {
LayoutInflater inflater = LayoutInflater.from(getActivity());
TextView item = (TextView) inflater.inflate(R.layout.flexbox_item, flexboxLayout, false);
TextView textView = (TextView) item.findViewById(android.R.id.text1);
textView.setText(getActivity().getString(R.string.item_default, flexboxLayout.getChildCount()));
FlexboxLayout.LayoutParams layoutParams = (FlexboxLayout.LayoutParams) item.getLayoutParams();
item.setLayoutParams(layoutParams);
item.setOnLongClickListener(this);
item.setOnClickListener(this);
flexboxLayout.addView(item);
}
示例9: testFlexBasisPercent_wrap
import com.google.android.flexbox.FlexboxLayout; //导入方法依赖的package包/类
@Test
@FlakyTest(tolerance = TOLERANCE)
public void testFlexBasisPercent_wrap() throws Throwable {
final FlexboxTestActivity activity = mActivityRule.getActivity();
mActivityRule.runOnUiThread(new Runnable() {
@Override
public void run() {
activity.setContentView(R.layout.activity_flex_basis_percent_test);
}
});
FlexboxLayout flexboxLayout = (FlexboxLayout) activity.findViewById(R.id.flexbox_layout);
// The text1 length is 50%, the text2 length is 60% and the wrap property is FLEX_WRAP_WRAP,
// the text2 should be on the second flex line.
assertThat(flexboxLayout.getFlexWrap(), is(FlexboxLayout.FLEX_WRAP_WRAP));
onView(withId(R.id.text1)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text1)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text2)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
onView(withId(R.id.text2)).check(isBelow(withId(R.id.text1)));
onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
TextView textView1 = (TextView) activity.findViewById(R.id.text1);
TextView textView2 = (TextView) activity.findViewById(R.id.text2);
FlexboxLayout.LayoutParams lp1 = (FlexboxLayout.LayoutParams) textView1.getLayoutParams();
FlexboxLayout.LayoutParams lp2 = (FlexboxLayout.LayoutParams) textView2.getLayoutParams();
assertThat(textView1.getWidth(),
is(Math.round(flexboxLayout.getWidth() * lp1.flexBasisPercent)));
assertThat(textView2.getWidth(),
is(Math.round(flexboxLayout.getWidth() * lp2.flexBasisPercent)));
}
示例10: createTextView
import com.google.android.flexbox.FlexboxLayout; //导入方法依赖的package包/类
private TextView createTextView(Context context, String text, int order) {
TextView textView = new TextView(context);
textView.setText(text);
FlexboxLayout.LayoutParams lp = new FlexboxLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
lp.order = order;
textView.setLayoutParams(lp);
return textView;
}
示例11: createDefaultLayoutParams
import com.google.android.flexbox.FlexboxLayout; //导入方法依赖的package包/类
/**
* Creates a new {@link FlexboxLayout.LayoutParams} based on the stored default values in
* the SharedPreferences.
*
* @return a {@link FlexboxLayout.LayoutParams} instance
*/
private FlexboxLayout.LayoutParams createDefaultLayoutParams() {
FlexboxLayout.LayoutParams lp = new FlexboxLayout.LayoutParams(
Util.dpToPixel(this,
readPreferenceAsInteger(getString(R.string.new_width_key), DEFAULT_WIDTH)),
Util.dpToPixel(this, readPreferenceAsInteger(getString(R.string.new_height_key),
DEFAULT_HEIGHT)));
lp.order = readPreferenceAsInteger(getString(R.string.new_flex_item_order_key), "1");
lp.flexGrow = readPreferenceAsFloat(getString(R.string.new_flex_grow_key), "0.0");
lp.flexShrink = readPreferenceAsFloat(getString(R.string.new_flex_shrink_key), "1.0");
int flexBasisPercent = readPreferenceAsInteger(
getString(R.string.new_flex_basis_percent_key), "-1");
lp.flexBasisPercent = flexBasisPercent == -1 ? -1 : (float) (flexBasisPercent / 100.0);
return lp;
}
示例12: onFlexItemChanged
import com.google.android.flexbox.FlexboxLayout; //导入方法依赖的package包/类
@Override
public void onFlexItemChanged(FlexItem flexItem) {
View view = mFlexboxLayout.getChildAt(flexItem.index);
FlexboxLayout.LayoutParams lp = flexItem.toLayoutParams(MainActivity.this);
view.setLayoutParams(lp);
// TODO: Update the layout only related views
mFlexboxLayout.requestLayout();
}
示例13: toLayoutParams
import com.google.android.flexbox.FlexboxLayout; //导入方法依赖的package包/类
public FlexboxLayout.LayoutParams toLayoutParams(Context context) {
FlexboxLayout.LayoutParams lp = new FlexboxLayout.LayoutParams(
Util.dpToPixel(context, width),
Util.dpToPixel(context, height));
lp.order = order;
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;
return lp;
}
示例14: addView
import com.google.android.flexbox.FlexboxLayout; //导入方法依赖的package包/类
private void addView(Sponsor sponsor, FlexboxLayout container) {
SponsorImageView imageView = new SponsorImageView(getActivity());
imageView.bindData(sponsor, v -> {
if (TextUtils.isEmpty(sponsor.url))
return;
analyticsTracker.sendEvent("sponsor", sponsor.url);
AppUtil.showWebPage(getActivity(), sponsor.url);
});
FlexboxLayout.LayoutParams params = new FlexboxLayout.LayoutParams(
FlexboxLayout.LayoutParams.WRAP_CONTENT, FlexboxLayout.LayoutParams.WRAP_CONTENT);
int margin = (int) getResources().getDimension(R.dimen.spacing_small);
params.setMargins(margin, margin, 0, 0);
container.addView(imageView, params);
}
示例15: generateLayoutParams
import com.google.android.flexbox.FlexboxLayout; //导入方法依赖的package包/类
@NonNull
private FlexboxLayout.LayoutParams generateLayoutParams() {
final FlexboxLayout.LayoutParams params = new FlexboxLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
final int margin = getResources().getDimensionPixelOffset(R.dimen.backup_phrase_spacing);
params.setMargins(0, 0, margin, margin);
return params;
}