本文整理汇总了Java中android.widget.LinearLayout.setGravity方法的典型用法代码示例。如果您正苦于以下问题:Java LinearLayout.setGravity方法的具体用法?Java LinearLayout.setGravity怎么用?Java LinearLayout.setGravity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.LinearLayout
的用法示例。
在下文中一共展示了LinearLayout.setGravity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getItemView
import android.widget.LinearLayout; //导入方法依赖的package包/类
private View getItemView() {
LinearLayout mItemLayout = new LinearLayout(this);
mItemLayout.setGravity(Gravity.CENTER);
mItemLayout.setOrientation(LinearLayout.VERTICAL);
ImageView mImageView = new ImageView(this);
LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(ui_dip2px(50), ui_dip2px(50));
mImageView.setLayoutParams(mParams);
mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
TextView mTextView = new TextView(this);
mTextView.setGravity(Gravity.CENTER);
mTextView.setFilters(new InputFilter[]{new InputFilter.LengthFilter(4)});
mTextView.setTextColor(Color.BLUE);
mItemLayout.addView(mImageView);
mItemLayout.addView(mTextView);
return mItemLayout;
}
示例2: addItem
import android.widget.LinearLayout; //导入方法依赖的package包/类
private void addItem(SwipeMenuItem item, int id) {
LayoutParams params = new LayoutParams(item.getWidth(),
LayoutParams.MATCH_PARENT);
LinearLayout parent = new LinearLayout(getContext());
parent.setId(id);
parent.setGravity(Gravity.CENTER);
parent.setOrientation(LinearLayout.VERTICAL);
parent.setLayoutParams(params);
parent.setBackgroundDrawable(item.getBackground());
parent.setOnClickListener(this);
addView(parent);
if (item.getIcon() != null) {
parent.addView(createIcon(item));
}
if (!TextUtils.isEmpty(item.getTitle())) {
parent.addView(createTitle(item));
}
}
示例3: initPageNumber
import android.widget.LinearLayout; //导入方法依赖的package包/类
/**
* 初始化数字页码
*/
private void initPageNumber() {
if (IndicatorManager.getInstance().getIndicatorType() == NUMBER_INDICATOR) {
mPageNumberLayout = new LinearLayout(getContext());
mPageNumberLayout.setOrientation(LinearLayout.HORIZONTAL);
mPageNumberLayout.setGravity(Gravity.CENTER);
mPageNumberLayout.removeAllViews();
mNumberViews = new NumberView[mInfos.size()];
for (int i = 0; i < mInfos.size(); i++) {
NumberView numberView;
if (i == mSelectedIndex) {
numberView = new NumberView(getContext(), NumberView.mNumberViewSelectedColor);
} else {
numberView = new NumberView(getContext(), NumberView.mNumberViewNormalColor);
}
numberView.setNumber(i + 1);
mNumberViews[i] = numberView;
mPageNumberLayout.addView(mNumberViews[i]);
}
}
}
示例4: addItem
import android.widget.LinearLayout; //导入方法依赖的package包/类
public void addItem(ButtonItem...items){
for(ButtonItem item:items) {
if(!itemList.contains(item)){
item.setScaleX(0);
item.setScaleY(0);
item.setBackgroundColor(Color.TRANSPARENT);
LinearLayout layout=new LinearLayout(getContext());
itemList.add(item);
layout.setGravity(Gravity.CENTER);
layout.addView(item);
wrappedItems.add(layout);
}
}
}
示例5: setEditViewsName
import android.widget.LinearLayout; //导入方法依赖的package包/类
/**
* 设置编辑列表VIEW
*
* @param names 编辑view 的name
* @return this
*/
public BaseDialog setEditViewsName(List<String> names) {
if (middleLayout.getChildCount() > 0) {
middleLayout.removeAllViews();
}
for (String name :
names) {
TextView textView = new TextView(getContext());
textView.setText(name);
EditText editText = new EditText(getContext());
editText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
editText.setHint("请输入" + name);
editText.setPadding(10, 0, 0, 0);
editText.setHintTextColor(Color.BLUE);
LinearLayout child = new LinearLayout(getContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
child.setOrientation(LinearLayout.HORIZONTAL);
child.setGravity(Gravity.CENTER_VERTICAL);
child.setLayoutParams(params);
child.addView(textView);
child.addView(editText);
middleLayout.addView(child);
}
return this;
}
示例6: onCreateView
import android.widget.LinearLayout; //导入方法依赖的package包/类
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Context context = getActivity();
FrameLayout root = new FrameLayout(context);
LinearLayout pframe = new LinearLayout(context);
pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
pframe.setOrientation(1);
pframe.setVisibility(8);
pframe.setGravity(17);
pframe.addView(new ProgressBar(context, null, 16842874), new LayoutParams(-2, -2));
root.addView(pframe, new LayoutParams(-1, -1));
FrameLayout lframe = new FrameLayout(context);
lframe.setId(INTERNAL_LIST_CONTAINER_ID);
TextView tv = new TextView(getActivity());
tv.setId(INTERNAL_EMPTY_ID);
tv.setGravity(17);
lframe.addView(tv, new LayoutParams(-1, -1));
ListView lv = new ListView(getActivity());
lv.setId(16908298);
lv.setDrawSelectorOnTop(false);
lframe.addView(lv, new LayoutParams(-1, -1));
root.addView(lframe, new LayoutParams(-1, -1));
root.setLayoutParams(new LayoutParams(-1, -1));
return root;
}
示例7: makeContentView
import android.widget.LinearLayout; //导入方法依赖的package包/类
/**
* @see #makeHeaderView()
* @see #makeCenterView()
* @see #makeFooterView()
*/
@Override
protected final View makeContentView() {
LinearLayout rootLayout = new LinearLayout(activity);
rootLayout.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
rootLayout.setBackgroundColor(backgroundColor);
rootLayout.setOrientation(LinearLayout.VERTICAL);
rootLayout.setGravity(Gravity.CENTER);
int padding = ConvertUtils.toPx(activity, contentPaddingLefAndRight);
rootLayout.setPadding(padding, 0, padding, 0);
rootLayout.setClipToPadding(false);
View headerView = makeHeaderView();
//2017-8-10 lyy 调整头部按钮的显示位置到底部
// if (headerView != null) {
// rootLayout.addView(headerView);
// }
// if (topLineVisible) {
// View lineView = new View(activity);
// lineView.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, topLineHeightPixels));
// lineView.setBackgroundColor(topLineColor);
// rootLayout.addView(lineView);
// }
rootLayout.addView(makeCenterView(), new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1.0f));
View footerView = makeFooterView();
if (footerView != null) {
footerView.setPadding(padding, 0, padding, 0);
rootLayout.addView(footerView);
}
if (topLineVisible) {
View lineView = new View(activity);
lineView.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, topLineHeightPixels));
lineView.setBackgroundColor(topLineColor);
rootLayout.addView(lineView);
}
if (headerView != null) {
rootLayout.addView(headerView);
}
return rootLayout;
}
示例8: makeCenterView
import android.widget.LinearLayout; //导入方法依赖的package包/类
@Override
@NonNull
protected View makeCenterView() {
if (options.size() == 0) {
throw new IllegalArgumentException("please initial options at first, can't be empty");
}
LinearLayout layout = new LinearLayout(activity);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.setGravity(Gravity.CENTER);
WheelView optionView = new WheelView(activity);
optionView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
optionView.setTextSize(textSize);
optionView.setTextColor(textColorNormal, textColorFocus);
optionView.setLineVisible(lineVisible);
optionView.setLineColor(lineColor);
optionView.setOffset(offset);
layout.addView(optionView);
TextView labelView = new TextView(activity);
labelView.setLayoutParams(new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
labelView.setTextColor(textColorFocus);
labelView.setTextSize(textSize);
layout.addView(labelView);
if (!TextUtils.isEmpty(label)) {
labelView.setText(label);
}
if (TextUtils.isEmpty(selectedOption)) {
optionView.setItems(options);
} else {
optionView.setItems(options, selectedOption);
}
optionView.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
@Override
public void onSelected(boolean isUserScroll, int selectedIndex, String item) {
selectedOption = item;
}
});
return layout;
}
示例9: addResultListItem
import android.widget.LinearLayout; //导入方法依赖的package包/类
public void addResultListItem(String title, String value, LinearLayout netLayout) {
final float scale = activity.getResources().getDisplayMetrics().density;
final int leftRightItem = Helperfunctions.dpToPx(5, scale);
final int topBottomItem = Helperfunctions.dpToPx(5, scale);
final int leftRightDiv = Helperfunctions.dpToPx(0, scale);
final int topBottomDiv = Helperfunctions.dpToPx(0, scale);
final int heightDiv = Helperfunctions.dpToPx(1, scale);
final int topBottomImg = Helperfunctions.dpToPx(1, scale);
final LinearLayout netItemLayout = new LinearLayout(activity);
netItemLayout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
netItemLayout.setPadding(leftRightItem, topBottomItem, leftRightItem, topBottomItem);
netItemLayout.setGravity(Gravity.CENTER_VERTICAL);
final TextView itemTitle = new TextView(activity, null, R.style.listResultItemTitle);
itemTitle.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, 0.4f));
itemTitle.setWidth(0);
itemTitle.setGravity(Gravity.LEFT);
itemTitle.setText(title);
netItemLayout.addView(itemTitle);
final ImageView itemClassification = new ImageView(activity);
itemClassification.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.MATCH_PARENT, 0.1f));
itemClassification.setPadding(0, topBottomImg, 0, topBottomImg);
itemClassification.setImageDrawable(activity.getResources().getDrawable(
R.drawable.traffic_lights_none));
netItemLayout.addView(itemClassification);
final TextView itemValue = new TextView(activity, null, R.style.listResultItemValue);
itemValue.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, 0.5f));
itemValue.setWidth(0);
itemValue.setGravity(Gravity.LEFT);
itemValue.setText(value);
netItemLayout.addView(itemValue);
netLayout.addView(netItemLayout);
final View divider = new View(activity);
divider.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, heightDiv,
1));
divider.setPadding(leftRightDiv, topBottomDiv, leftRightDiv, topBottomDiv);
divider.setBackgroundResource(R.drawable.bg_trans_light_10);
netLayout.addView(divider);
netLayout.invalidate();
}
示例10: onPreExecute
import android.widget.LinearLayout; //导入方法依赖的package包/类
@Override
protected void onPreExecute() {
try {//sometime it crash if the user refresh while the list is already being refreshed
super.onPreExecute();
// Replace the ListView with a ProgressBar
mProgBar = new ProgressBar(volumeBrowserActivity, null,android.R.attr.progressBarStyleLarge);
// Set the layout to fill the screen
mListView = volumeBrowserActivity.getListView();
mLayout = (LinearLayout) mListView.getParent();
if (mLayout==null) return;
mLayout.setGravity(Gravity.CENTER);
mLayout.setLayoutParams(new FrameLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
// Set the ProgressBar in the center of the layout
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.CENTER;
mProgBar.setLayoutParams(layoutParams);
// Replace the ListView with the ProgressBar
mLayout.removeView(mListView);
mLayout.addView(mProgBar);
mProgBar.setVisibility(View.VISIBLE);
} catch (Exception e){
e.printStackTrace();
}
}
示例11: setupViews
import android.widget.LinearLayout; //导入方法依赖的package包/类
private void setupViews() {
linearLayout = new LinearLayout(getContext());
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams
.MATCH_PARENT,FrameLayout
.LayoutParams.MATCH_PARENT);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setGravity(Gravity.CENTER);
addView(linearLayout,lp);
}
示例12: getView
import android.widget.LinearLayout; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final DialogMenuItem item = contents.get(position);
LinearLayout ll_item = new LinearLayout(context);
ll_item.setOrientation(LinearLayout.HORIZONTAL);
ll_item.setGravity(Gravity.CENTER_VERTICAL);
ImageView iv_item = new ImageView(context);
iv_item.setPadding(0, 0, dp2px(15), 0);
ll_item.addView(iv_item);
TextView tv_item = new TextView(context);
tv_item.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
tv_item.setSingleLine(true);
tv_item.setTextColor(itemTextColor);
tv_item.setTextSize(TypedValue.COMPLEX_UNIT_SP, itemTextSize_SP);
ll_item.addView(tv_item);
float radius = dp2px(cornerRadius_DP);
if (isTitleShow) {
ll_item.setBackgroundDrawable((CornerUtils.listItemSelector(radius, Color.TRANSPARENT, itemPressColor,
position == contents.size() - 1)));
} else {
ll_item.setBackgroundDrawable(CornerUtils.listItemSelector(radius, Color.TRANSPARENT, itemPressColor,
contents.size(), position));
}
int left = item.resId == 0 ? dp2px(18) : dp2px(16);
int top = dp2px(10);
int right = 0;
int bottom = dp2px(10);
ll_item.setPadding(left + itemExtraLeft, top + itemExtraTop, right + itemExtraRight, bottom + itemExtraBottom);
iv_item.setImageResource(item.resId);
tv_item.setText(item.operName);
iv_item.setVisibility(item.resId == 0 ? View.GONE : View.VISIBLE);
return ll_item;
}
示例13: makeContentView
import android.widget.LinearLayout; //导入方法依赖的package包/类
/**
* @see #makeHeaderView()
* @see #makeCenterView()
* @see #makeFooterView()
*/
@Override
protected final View makeContentView() {
LinearLayout rootLayout = new LinearLayout(activity);
rootLayout.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
rootLayout.setBackgroundColor(Color.WHITE);
rootLayout.setOrientation(LinearLayout.VERTICAL);
rootLayout.setGravity(Gravity.CENTER);
rootLayout.setPadding(0, 0, 0, 0);
rootLayout.setClipToPadding(false);
View headerView = makeHeaderView();
if (headerView != null) {
rootLayout.addView(headerView);
}
if (topLineVisible) {
View lineView = new View(activity);
lineView.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, 1));
lineView.setBackgroundColor(topLineColor);
rootLayout.addView(lineView);
}
rootLayout.addView(makeCenterView(), new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1.0f));
View footerView = makeFooterView();
if (footerView != null) {
rootLayout.addView(footerView);
}
return rootLayout;
}
示例14: initView
import android.widget.LinearLayout; //导入方法依赖的package包/类
/**
* 初始化子View
*
* @param context
*/
private void initView(Context context) {
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
LayoutParams dividerParams = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, mDividerHeight);
mLeftLayout = new LinearLayout(context);
mCenterLayout = new LinearLayout(context);
mRightLayout = new LinearLayout(context);
mStatusView = new View(context);
mDividerView = new View(context);
mLeftLayout.setGravity(Gravity.CENTER_VERTICAL);
mCenterLayout.setOrientation(LinearLayout.VERTICAL);
mRightLayout.setGravity(Gravity.CENTER_VERTICAL);
mLeftTv = new TextView(context);
mLeftTv.setGravity(Gravity.CENTER);
mLeftTv.setLines(1);
mTitleMain = new TextView(context);
mTitleSub = new TextView(context);
mRightTv = new TextView(context);
mRightTv.setGravity(Gravity.CENTER);
mRightTv.setLines(1);
mLeftLayout.addView(mLeftTv, params);
mRightLayout.addView(mRightTv, params);
addView(mLeftLayout, params);//添加左边容器
addView(mCenterLayout, params);//添加中间容器
addView(mRightLayout, params);//添加右边容器
addView(mDividerView, dividerParams);//添加下划线View
addView(mStatusView);//添加状态栏View
}
示例15: init
import android.widget.LinearLayout; //导入方法依赖的package包/类
/**
* Initialize our card with passed in attributes.
*
* @param context Context our view is in
* @param attrs Attributes passed into the constructor from code or the layout xml
*/
private void init(Context context, AttributeSet attrs) {
// Get custom attributes
TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.SetGameCardView);
// Set some defaults
mIsChecked = false;
mIsHighlighted = false;
try {
mAspectRatioWidth = attributes.getInt(R.styleable.SetGameCardView_aspectWidth, 2);
mAspectRatioHeight = attributes.getInt(R.styleable.SetGameCardView_aspectHeight, 3);
// Defaults to Oval:Red:One:Solid if not set
mShape = attributes.getInt(R.styleable.SetGameCardView_symbol_shape, 0);
mColor = attributes.getInt(R.styleable.SetGameCardView_symbol_color, 0);
mCount = attributes.getInt(R.styleable.SetGameCardView_symbol_count, 0);
mFill = attributes.getInt(R.styleable.SetGameCardView_symbol_fill, 0);
} finally {
attributes.recycle();
}
/*
* Set up 2D array to get the correct drawable based on shape and fill
* +--------------------------------------------------+
* | oval_solid | oval_open | oval_stripe |
* | diamond_solid | diamond_open | diamond_stripe |
* | squiggle_solid | squiggle_open | squiggle_stripe |
* +--------------------------------------------------+
*/
mShapeFill[0][0] = R.drawable.ic_set_icons_emerald_solid;
mShapeFill[0][1] = R.drawable.ic_set_icons_emerald_open;
mShapeFill[0][2] = R.drawable.ic_set_icons_emerald_stripe;
mShapeFill[1][0] = R.drawable.ic_set_icons_diamond_solid;
mShapeFill[1][1] = R.drawable.ic_set_icons_diamond_open;
mShapeFill[1][2] = R.drawable.ic_set_icons_diamond_stripe;
mShapeFill[2][0] = R.drawable.ic_set_icons_pear_solid;
mShapeFill[2][1] = R.drawable.ic_set_icons_pear_open;
mShapeFill[2][2] = R.drawable.ic_set_icons_pear_stripe;
/*
* Add a LinearLayout to the card's frame layout to hold the symbols
*/
mLinearLayout = new LinearLayout(mContext);
mLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
mLinearLayout.setGravity(Gravity.CENTER);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
);
mLinearLayout.setLayoutParams(layoutParams);
this.setCardBackgroundColor(
ContextCompat.getColor(getContext(), R.color.card_background_normal));
this.addView(mLinearLayout);
drawSymbols();
}