本文整理匯總了Java中android.view.Gravity.CENTER_VERTICAL屬性的典型用法代碼示例。如果您正苦於以下問題:Java Gravity.CENTER_VERTICAL屬性的具體用法?Java Gravity.CENTER_VERTICAL怎麽用?Java Gravity.CENTER_VERTICAL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.view.Gravity
的用法示例。
在下文中一共展示了Gravity.CENTER_VERTICAL屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getBodyBottom
private LinearLayout getBodyBottom() {
LinearLayout llBottom = new LinearLayout(getContext());
llBottom.setLayoutParams(new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
String platform = String.valueOf(reqData.get("platform"));
LinearLayout line = getAtLine(platform);
if (line != null) {
llBottom.addView(line);
}
// 字數統計
tvCounter = new TextView(getContext());
tvCounter.setText(String.valueOf(MAX_TEXT_COUNT));
tvCounter.setTextColor(0xffcfcfcf);
tvCounter.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
tvCounter.setTypeface(Typeface.DEFAULT_BOLD);
LinearLayout.LayoutParams lpCounter = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpCounter.gravity = Gravity.CENTER_VERTICAL;
tvCounter.setLayoutParams(lpCounter);
llBottom.addView(tvCounter);
return llBottom;
}
示例2: getBodyBottom
private LinearLayout getBodyBottom() {
LinearLayout llBottom = new LinearLayout(getContext());
llBottom.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
LinearLayout line = getAtLine(platforms.get(0).getName());
if (line != null) {
llBottom.addView(line);
}
// Words counter
tvCounter = new TextView(getContext());
tvCounter.setText(String.valueOf(MAX_TEXT_COUNT));
tvCounter.setTextColor(0xffcfcfcf);
tvCounter.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
tvCounter.setTypeface(Typeface.DEFAULT_BOLD);
LayoutParams lpCounter = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpCounter.gravity = Gravity.CENTER_VERTICAL;
tvCounter.setLayoutParams(lpCounter);
llBottom.addView(tvCounter);
return llBottom;
}
示例3: getItemViewType
@Override
public int getItemViewType(int position) {
Snap snap = mSnaps.get(position);
switch (snap.getGravity()) {
case Gravity.CENTER_VERTICAL:
return VERTICAL;
case Gravity.CENTER_HORIZONTAL:
return HORIZONTAL;
case Gravity.START:
return HORIZONTAL;
case Gravity.TOP:
return VERTICAL;
case Gravity.END:
return HORIZONTAL;
case Gravity.BOTTOM:
return VERTICAL;
}
return HORIZONTAL;
}
示例4: load
public static String load(String text, final AdvancedDisplay parent, final int pos) {
final CalculatorEditText et = new CalculatorEditText(parent);
et.setText(text);
et.setSelection(0);
if(parent.mKeyListener != null) et.setKeyListener(parent.mKeyListener);
if(parent.mFactory != null) et.setEditableFactory(parent.mFactory);
et.setBackgroundResource(android.R.color.transparent);
et.setTextAppearance(parent.getContext(), R.style.display_style);
et.setPadding(5, 0, 5, 0);
et.setEnabled(parent.isEnabled());
AdvancedDisplay.LayoutParams params = new AdvancedDisplay.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER_VERTICAL;
et.setLayoutParams(params);
parent.addView(et, pos);
return "";
}
示例5: getGravity
private int getGravity(String gravity) {
switch (gravity) {
case "CENTER":
return Gravity.CENTER;
case "CENTER_VERTICAL":
return Gravity.CENTER_VERTICAL;
case "TOP":
return Gravity.TOP;
case "LEFT":
return Gravity.LEFT;
case "RIGHT":
return Gravity.RIGHT;
case "BOTTOM":
return Gravity.BOTTOM;
case "START":
return Gravity.START;
case "END":
return Gravity.END;
default:
return Gravity.CENTER_VERTICAL;
}
}
開發者ID:cesardeazevedo,項目名稱:react-native-collapsing-toolbar,代碼行數:22,代碼來源:CollapsingToolbarLayoutManager.java
示例6: PRTHeader
public PRTHeader(Context context) {
super(context);
int[] size = ResHelper.getScreenSize(context);
float screenWidth = size[0] < size[1] ? size[0] : size[1];
float ratio = screenWidth / DESIGN_SCREEN_WIDTH;
setOrientation(VERTICAL);
LinearLayout llInner = new LinearLayout(context);
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER_HORIZONTAL;
addView(llInner, lp);
ivArrow = new RotateImageView(context);
int resId = ResHelper.getBitmapRes(context, "ssdk_oks_ptr_ptr");
if (resId > 0) {
ivArrow.setImageResource(resId);
}
int avatarWidth = (int) (ratio * DESIGN_AVATAR_WIDTH);
lp = new LayoutParams(avatarWidth, avatarWidth);
lp.gravity = Gravity.CENTER_VERTICAL;
int avataPadding = (int) (ratio * DESIGN_AVATAR_PADDING);
lp.topMargin = lp.bottomMargin = avataPadding;
llInner.addView(ivArrow, lp);
pbRefreshing = new ProgressBar(context);
resId = ResHelper.getBitmapRes(context, "ssdk_oks_classic_progressbar");
Drawable pbdrawable = context.getResources().getDrawable(resId);
pbRefreshing.setIndeterminateDrawable(pbdrawable);
llInner.addView(pbRefreshing, lp);
pbRefreshing.setVisibility(View.GONE);
tvHeader = new TextView(getContext());
tvHeader.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
tvHeader.setPadding(avataPadding, 0, avataPadding, 0);
tvHeader.setTextColor(0xff09bb07);
lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER_VERTICAL;
llInner.addView(tvHeader, lp);
}
示例7: attributeDell
private void attributeDell(String str)
{
setHorizontalFadingEdgeEnabled(fadingEdgeEnabled && getTextWidth(str) >= getWidth());
if (gravity == -1)
{
gravity = getGravity();
}
if (isScrolling)
{
if (getTextWidth(str) > getWidth())
{
if (!(getGravity() == Gravity.START || getGravity() == (Gravity.TOP | Gravity.START)
|| getGravity() == (Gravity.BOTTOM | Gravity.START)
|| getGravity() == (Gravity.CENTER_VERTICAL | Gravity.START)))
{
setSupperGravity(Gravity.START);
}
}
else
{
setSupperGravity(gravity);
}
}
else
{
if (getTextWidth(str) > getWidth())
{
setSupperGravity(Gravity.START);
}
else if (getTextWidth(str) <= getWidth())
{
setSupperGravity(gravity);
}
}
}
示例8: PRTHeader
public PRTHeader(Context context) {
super(context);
setOrientation(VERTICAL);
LinearLayout llInner = new LinearLayout(context);
LinearLayout.LayoutParams lpInner = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpInner.gravity = Gravity.CENTER_HORIZONTAL;
addView(llInner, lpInner);
ivArrow = new RotateImageView(context);
int resId = getBitmapRes(context, "ssdk_oks_ptr_ptr");
if (resId > 0) {
ivArrow.setImageResource(resId);
}
int dp_32 = dipToPx(context, 32);
LayoutParams lpIv = new LayoutParams(dp_32, dp_32);
lpIv.gravity = Gravity.CENTER_VERTICAL;
llInner.addView(ivArrow, lpIv);
pbRefreshing = new ProgressBar(context);
llInner.addView(pbRefreshing, lpIv);
pbRefreshing.setVisibility(View.GONE);
tvHeader = new TextView(getContext());
tvHeader.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
tvHeader.setGravity(Gravity.CENTER);
int dp_10 = cn.sharesdk.framework.utils.R.dipToPx(getContext(), 10);
tvHeader.setPadding(dp_10, dp_10, dp_10, dp_10);
tvHeader.setTextColor(0xff000000);
LayoutParams lpTv = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lpTv.gravity = Gravity.CENTER_VERTICAL;
llInner.addView(tvHeader, lpTv);
}
示例9: SnackbarAddView
/**
* 向Snackbar中添加view
* @param snackbar
* @param layoutId
* @param index 新加布局在Snackbar中的位置
*/
public static void SnackbarAddView( Snackbar snackbar,int layoutId,int index) {
View snackbarview = snackbar.getView();
Snackbar.SnackbarLayout snackbarLayout=(Snackbar.SnackbarLayout)snackbarview;
View add_view = LayoutInflater.from(snackbarview.getContext()).inflate(layoutId,null);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
p.gravity= Gravity.CENTER_VERTICAL;
snackbarLayout.addView(add_view,index,p);
}
示例10: getFrameLayoutParams
private FrameLayout.LayoutParams getFrameLayoutParams(Boolean left){
FrameLayout.LayoutParams params =new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
if (left == null){
params.gravity = Gravity.CENTER;
return params;
}
if (left){
params.gravity = Gravity.LEFT|Gravity.CENTER_VERTICAL;
}else {
params.gravity = Gravity.RIGHT|Gravity.CENTER_VERTICAL;
}
return params;
}
示例11: FriendListItem
public FriendListItem(Context context, float ratio) {
super(context);
int itemPadding = (int) (ratio * DESIGN_ITEM_PADDING);
setPadding(itemPadding, 0, itemPadding, 0);
setMinimumHeight((int) (ratio * DESIGN_ITEM_HEIGHT));
setBackgroundColor(0xffffffff);
ivCheck = new ImageView(context);
LayoutParams lp = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER_VERTICAL;
addView(ivCheck, lp);
aivIcon = new AsyncImageView(context);
int avatarWidth = (int) (ratio * DESIGN_AVATAR_WIDTH);
lp = new LayoutParams(avatarWidth, avatarWidth);
lp.gravity = Gravity.CENTER_VERTICAL;
int avatarMargin = (int) (ratio * DESIGN_AVATAR_PADDING);
lp.setMargins(avatarMargin, 0, avatarMargin, 0);
addView(aivIcon, lp);
tvName = new TextView(context);
tvName.setTextColor(0xff000000);
tvName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
tvName.setSingleLine();
lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER_VERTICAL;
lp.weight = 1;
addView(tvName, lp);
int resId = ResHelper.getBitmapRes(context, "ssdk_oks_classic_check_checked");
if (resId > 0) {
bmChd = BitmapFactory.decodeResource(context.getResources(), resId);
}
resId = ResHelper.getBitmapRes(getContext(), "ssdk_oks_classic_check_default");
if (resId > 0) {
bmUnch = BitmapFactory.decodeResource(context.getResources(), resId);
}
}
示例12: alignViews
public void alignViews(String horizontal, String vertical) {
int h = Gravity.LEFT;
switch (horizontal) {
case "left":
h = Gravity.LEFT;
break;
case "center":
h = Gravity.CENTER_HORIZONTAL;
break;
case "right":
h = Gravity.RIGHT;
break;
}
int v = Gravity.TOP;
switch (vertical) {
case "top":
v = Gravity.TOP;
break;
case "center":
v = Gravity.CENTER_VERTICAL;
break;
case "bottom":
v = Gravity.BOTTOM;
break;
}
setGravity(h | v);
}
示例13: addView
/**
* 向Snackbar中添加view
*
* @param snackbar
* @param layoutId
* @param index 新加布局在Snackbar中的位置
*/
public static void addView(Snackbar snackbar, int layoutId, int index) {
View snackbarview = snackbar.getView();
Snackbar.SnackbarLayout snackbarLayout = (Snackbar.SnackbarLayout) snackbarview;
View add_view = LayoutInflater.from(snackbarview.getContext()).inflate(layoutId, null);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams
.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
p.gravity = Gravity.CENTER_VERTICAL;
snackbarLayout.addView(add_view, index, p);
}
示例14: initSearchView
private void initSearchView() {
SearchView searchView = mBinding.svSearch;
//設置搜索框左邊距
LinearLayout editFrame = (LinearLayout) findViewById(R.id.search_edit_frame);
LinearLayout.LayoutParams editP = (LayoutParams) editFrame.getLayoutParams();
editP.leftMargin = 0;
editP.rightMargin = 0;
ImageView imageView = (ImageView) findViewById(R.id.search_mag_icon);
imageView.setAdjustViewBounds(true);
imageView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
LinearLayout.LayoutParams lp3 = (LayoutParams) imageView.getLayoutParams();
lp3.gravity = Gravity.CENTER_VERTICAL;
lp3.leftMargin = (int) (DensityUtil.dip2px(8f) * DensityUtil.getBaseScale(getContext()));
lp3.rightMargin = (int) (DensityUtil.dip2px(-2f) * DensityUtil.getBaseScale(getContext()));
View view = searchView.findViewById(R.id.search_plate);
view.setBackgroundColor(getResources().getColor(R.color.colorTransparent));
EditText editText = (EditText) searchView.findViewById(R.id.search_src_text);
editText.setBackgroundColor(Color.TRANSPARENT);
editText.setTextSize(11.5f);
editText.setTextColor(getResources().getColor(R.color.colorText));
editText.setHintTextColor(getResources().getColor(R.color.colorHint));
try {
Field fCursorDrawableRes = TextView.class.getDeclaredField("mCursorDrawableRes");
fCursorDrawableRes.setAccessible(true);
int mCursorDrawableRes = fCursorDrawableRes.getInt(editText);
Field fEditor = TextView.class.getDeclaredField("mEditor");
fEditor.setAccessible(true);
Object editor = fEditor.get(editText);
Class<?> clazz = editor.getClass();
Field fCursorDrawable = clazz.getDeclaredField("mCursorDrawable");
fCursorDrawable.setAccessible(true);
if (mCursorDrawableRes <= 0) return;
Drawable cursorDrawable = ContextCompat.getDrawable(searchView.getContext(), mCursorDrawableRes);
if (cursorDrawable == null) return;
Drawable tintDrawable = DrawableCompat.wrap(cursorDrawable);
DrawableCompat.setTintList(tintDrawable, ColorStateList.valueOf(ContextCompat.getColor(getContext(), R.color.bg_search)));
Drawable[] drawables = new Drawable[]{tintDrawable, tintDrawable};
fCursorDrawable.set(editor, drawables);
} catch (Throwable t) {
t.printStackTrace();
}
}
示例15: createView
private View createView(final Context context, RemoteViews remoteViews, boolean isBig, boolean systemId) {
if (remoteViews == null)
return null;
Context base = mNotificationCompat.getHostContext();
init(base);
VLog.v(TAG, "createView:big=" + isBig + ",system=" + systemId);
// TODO 需要適配
int height = isBig ? notification_max_height : notification_min_height;
int width = mWidthCompat.getNotificationWidth(base, notification_panel_width, height,
notification_side_padding);
VLog.v(TAG, "createView:getNotificationWidth=" + width);
ViewGroup frameLayout = new FrameLayout(context);
VLog.v(TAG, "createView:apply");
View view1 = apply(context, remoteViews);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
params.gravity = Gravity.CENTER_VERTICAL;
frameLayout.addView(view1, params);
if (view1 instanceof ViewGroup) {
VLog.v(TAG, "createView:fixTextView");
fixTextView((ViewGroup) view1);
}
int mode;
// TODO 各種適配
if (systemId) {
mode = View.MeasureSpec.EXACTLY;
} else {
if (isBig) {
mode = View.MeasureSpec.AT_MOST;
} else {
mode = View.MeasureSpec.EXACTLY;
}
}
VLog.v(TAG, "createView:layout");
View mCache = frameLayout;
mCache.layout(0, 0, width, height);
mCache.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(height, mode));
mCache.layout(0, 0, width, mCache.getMeasuredHeight());
VLog.v(TAG, "notification:systemId=" + systemId + ",max=%d/%d, szie=%d/%d", width, height,
mCache.getMeasuredWidth(), mCache.getMeasuredHeight());
return mCache;
}