List of usage examples for android.view Gravity CENTER_VERTICAL
int CENTER_VERTICAL
To view the source code for android.view Gravity CENTER_VERTICAL.
Click Source Link
From source file:org.michaelbel.bottomsheet.BottomSheetCell.java
public BottomSheetCell setIcon(@DrawableRes int resId, @ColorInt int color) { if (resId != 0) { Drawable res = ContextCompat.getDrawable(getContext(), resId); res.clearColorFilter();//from w w w.ja va 2 s . c o m res.mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY); iconView.setImageDrawable(res); FrameLayout.LayoutParams params2 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); params2.gravity = Gravity.START | Gravity.CENTER_VERTICAL; params2.leftMargin = Utils.dp(getContext(), 72); params2.rightMargin = Utils.dp(getContext(), 16); textView.setLayoutParams(params2); } else { FrameLayout.LayoutParams params2 = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); params2.gravity = Gravity.START | Gravity.CENTER_VERTICAL; params2.leftMargin = Utils.dp(getContext(), 16); params2.rightMargin = Utils.dp(getContext(), 16); textView.setLayoutParams(params2); } return this; }
From source file:de.mdxdave.materialbreadcrumbsnavigation.MaterialBreadcrumbsNavigation.java
public MaterialBreadcrumbsNavigation(Context context, AttributeSet attrs) { super(context, attrs); this.context = context; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MaterialBreadcrumbsNavigation, 0, 0); textColor = a.getColor(R.styleable.MaterialBreadcrumbsNavigation_textColor, ContextCompat.getColor(context, R.color.default_text)); indicatorColor = a.getColor(R.styleable.MaterialBreadcrumbsNavigation_arrowColor, ContextCompat.getColor(context, R.color.default_indicator)); backgroundColor = a.getColor(R.styleable.MaterialBreadcrumbsNavigation_backgroundColor, ContextCompat.getColor(context, R.color.default_background)); a.recycle();/* ww w . j a v a 2 s .c om*/ setOrientation(LinearLayout.HORIZONTAL); setGravity(Gravity.CENTER_VERTICAL); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); view = inflater.inflate(R.layout.main_view, this, true); horizontalScrollView = (HorizontalScrollView) view.findViewById(R.id.horizontalScrollView); horizontalScrollView.setBackgroundColor(backgroundColor); viewGroup = (ViewGroup) findViewById(R.id.parent_view); list = new ArrayList<>(); }
From source file:com.accia77.mockey.ui.PapiroActivity.java
@Override public void onResume() { super.onResume(); setTitle(MyApplication.getInstance().getMainActivityTitle()); massimaSceltaTextView = (TextView) findViewById(R.id.massimaSceltaTextView); String stringaTextView = currentEntry.getUserEditedEntry(); if (mDoShowAndPlayQuote) { // Custom toast con il testo della frase LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.papiro_toast, (ViewGroup) findViewById(R.id.toast_layout_root)); ImageView image = (ImageView) layout.findViewById(R.id.papiro_toast_image); image.setImageResource(R.drawable.ic_small_monkey_head); TextView text = (TextView) layout.findViewById(R.id.papiro_toast_text); text.setText(stringaTextView);// w w w .ja v a2s.c o m Toast toast = new Toast(this); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_SHORT); toast.setView(layout); toast.show(); // Playback of the quote if (currentEntry.getEntryType() == MySQLiteHelper.ENTRY_TYPE_PURE_TEXT) { MyApplication.getInstance().playSelection(currentEntry); } else if (currentEntry.getEntryType() == MySQLiteHelper.ENTRY_TYPE_AUDIO) { // No playback if the sd card is not mounted if (MyApplication.getInstance().isSdCardMounted(false)) { MyApplication.getInstance().playSelection(currentEntry); } } mDoShowAndPlayQuote = false; } if (MyApplication.getInstance().isDefaultPapiroLoaded()) { massimaSceltaTextView.setText(stringaTextView); massimaSceltaTextView.setVisibility(View.VISIBLE); } else massimaSceltaTextView.setVisibility(View.INVISIBLE); }
From source file:com.frostwire.android.gui.views.KeywordTagView.java
private KeywordTagView(Context context, AttributeSet attrs, KeywordFilter keywordFilter) { super(context, attrs); if (keywordFilter == null) { TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.KeywordTagView, 0, 0); count = attributes.getInteger(R.styleable.KeywordTagView_keyword_tag_count, 0); dismissible = attributes.getBoolean(R.styleable.KeywordTagView_keyword_tag_dismissable, true); boolean inclusive = attributes.getBoolean(R.styleable.KeywordTagView_keyword_tag_inclusive, true); String keyword = attributes.getString(R.styleable.KeywordTagView_keyword_tag_keyword); keywordFilter = new KeywordFilter(inclusive, keyword != null ? keyword : "[Text]", KeywordDetector.Feature.MANUAL_ENTRY); attributes.recycle();//from ww w. j a v a2 s . c o m } this.keywordFilter = keywordFilter; keywordSpan = new TextAppearanceSpan(getContext(), R.style.keywordTagText); countSpan = new TextAppearanceSpan(getContext(), R.style.keywordTagCount); layoutParams = new FlexboxLayout.LayoutParams(FlexboxLayout.LayoutParams.WRAP_CONTENT, toPx(34)); layoutParams.setMargins(0, 0, toPx(6), toPx(8)); setPadding(toPx(12), toPx(4), toPx(12), toPx(4)); setMinHeight(toPx(34)); setGravity(Gravity.CENTER_VERTICAL); setCompoundDrawablePadding(toPx(6)); }
From source file:com.kaedea.frontia.demo.DemoListFragment.java
@SuppressWarnings("ResourceType") public static View getItemViewLayout(Context context) { LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setGravity(Gravity.CENTER_VERTICAL); int[] attrs = new int[] { R.attr.selectableItemBackground }; TypedArray typedArray = context.obtainStyledAttributes(attrs); int backgroundResource = typedArray.getResourceId(0, 0); linearLayout.setBackgroundResource(backgroundResource); typedArray.recycle();//w w w . j a va 2 s . c o m LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); linearLayout.setLayoutParams(layoutParams); // Title TextView tvTitle = new TextView(context); tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16f); tvTitle.setMaxLines(1); tvTitle.setTextColor(Color.parseColor("#212121")); tvTitle.setId(ID_TITLE); layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.setMargins(Utils.dpToPx(context, 20f), Utils.dpToPx(context, 10f), Utils.dpToPx(context, 20f), 0); linearLayout.addView(tvTitle, layoutParams); // Sub Title TextView tvSubTitle = new TextView(context); tvSubTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14f); tvSubTitle.setMaxLines(2); tvSubTitle.setTextColor(Color.parseColor("#757575")); tvSubTitle.setId(ID_SUBTITLE); layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); layoutParams.setMargins(Utils.dpToPx(context, 20f), 0, Utils.dpToPx(context, 20f), Utils.dpToPx(context, 10f)); linearLayout.addView(tvSubTitle, layoutParams); return linearLayout; }
From source file:com.mishiranu.dashchan.content.service.AudioPlayerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); context = new ContextThemeWrapper(this, Preferences.getThemeResource()); setVolumeControlStream(AudioManager.STREAM_MUSIC); float density = ResourceUtils.obtainDensity(this); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); int padding = getResources().getDimensionPixelSize(R.dimen.dialog_padding_view); linearLayout.setPadding(padding, padding, padding, C.API_LOLLIPOP ? (int) (8f * density) : padding); textView = new TextView(context, null, android.R.attr.textAppearanceListItem); linearLayout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); textView.setPadding(0, 0, 0, 0);//from www .j a v a2s .co m textView.setEllipsize(TextUtils.TruncateAt.END); textView.setSingleLine(true); LinearLayout horizontal = new LinearLayout(context); horizontal.setOrientation(LinearLayout.HORIZONTAL); horizontal.setGravity(Gravity.CENTER_VERTICAL); horizontal.setPadding(0, (int) (16f * density), 0, 0); linearLayout.addView(horizontal, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); seekBar = new SeekBar(context); horizontal.addView(seekBar, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1)); seekBar.setPadding((int) (8f * density), 0, (int) (16f * density), 0); seekBar.setOnSeekBarChangeListener(this); button = new ImageButton(context); horizontal.addView(button, (int) (48f * density), (int) (48f * density)); button.setBackgroundResource( ResourceUtils.getResourceId(context, android.R.attr.listChoiceBackgroundIndicator, 0)); setPlayState(false); button.setOnClickListener(this); alertDialog = new AlertDialog.Builder(context).setView(linearLayout).setOnCancelListener(this) .setPositiveButton(R.string.action_stop, this).show(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(AudioPlayerService.ACTION_TOGGLE); intentFilter.addAction(AudioPlayerService.ACTION_CANCEL); LocalBroadcastManager.getInstance(this).registerReceiver(audioPlayerReceiver, intentFilter); bindService(new Intent(this, AudioPlayerService.class), this, 0); }
From source file:com.readystatesoftware.ghostlog.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Switch mainSwitch = new Switch(this); mainSwitch.setChecked(LogService.isRunning()); mainSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override// w ww . j a v a2 s . c o m public void onCheckedChanged(CompoundButton compoundButton, boolean b) { Intent intent = new Intent(MainActivity.this, LogService.class); if (b) { if (!LogService.isRunning()) { startService(intent); } } else { stopService(intent); } } }); final ActionBar bar = getActionBar(); final ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL; lp.rightMargin = getResources().getDimensionPixelSize(R.dimen.main_switch_margin_right); bar.setCustomView(mainSwitch, lp); bar.setDisplayShowCustomEnabled(true); mPrefs = PreferenceManager.getDefaultSharedPreferences(this); if (!mPrefs.getBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, false)) { PreferenceManager.setDefaultValues(this, R.xml.pref_filters, true); PreferenceManager.setDefaultValues(this, R.xml.pref_appearance, true); SharedPreferences.Editor edit = mPrefs.edit(); edit.putBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, true); edit.apply(); } }
From source file:org.telegram.ui.Components.PickerBottomLayout.java
public PickerBottomLayout(Context context, boolean darkTheme) { super(context); isDarkTheme = darkTheme;/* w ww . j a v a2s.c o m*/ setBackgroundColor(isDarkTheme ? 0xff1a1a1a : ContextCompat.getColor(context, R.color.background)); cancelButton = new TextView(context); cancelButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); cancelButton.setTextColor(isDarkTheme ? 0xffffffff : 0xff19a7e8); cancelButton.setGravity(Gravity.CENTER); cancelButton.setBackgroundDrawable(Theme.createBarSelectorDrawable( isDarkTheme ? Theme.ACTION_BAR_PICKER_SELECTOR_COLOR : Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, false)); cancelButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0); cancelButton.setText(LocaleController.getString("Cancel", R.string.Cancel).toUpperCase()); cancelButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); addView(cancelButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT)); doneButton = new LinearLayout(context); doneButton.setOrientation(LinearLayout.HORIZONTAL); doneButton.setBackgroundDrawable(Theme.createBarSelectorDrawable( isDarkTheme ? Theme.ACTION_BAR_PICKER_SELECTOR_COLOR : Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, false)); doneButton.setPadding(AndroidUtilities.dp(29), 0, AndroidUtilities.dp(29), 0); addView(doneButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT)); doneButtonBadgeTextView = new TextView(context); doneButtonBadgeTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); doneButtonBadgeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13); doneButtonBadgeTextView.setTextColor(0xffffffff); doneButtonBadgeTextView.setGravity(Gravity.CENTER); doneButtonBadgeTextView.setBackgroundResource(isDarkTheme ? R.drawable.photobadge : R.drawable.bluecounter); doneButtonBadgeTextView.setMinWidth(AndroidUtilities.dp(23)); doneButtonBadgeTextView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), AndroidUtilities.dp(1)); doneButton.addView(doneButtonBadgeTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 23, Gravity.CENTER_VERTICAL, 0, 0, 10, 0)); doneButtonTextView = new TextView(context); doneButtonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); doneButtonTextView.setTextColor(isDarkTheme ? 0xffffffff : 0xff19a7e8); doneButtonTextView.setGravity(Gravity.CENTER); doneButtonTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8)); doneButtonTextView.setText(LocaleController.getString("Send", R.string.Send).toUpperCase()); doneButtonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); doneButton.addView(doneButtonTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL)); }
From source file:org.goodev.droidddle.widget.SlidingTabLayout.java
public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Disable the Scroll Bar setHorizontalScrollBarEnabled(false); // Make sure that the Tab Strips fills this View setFillViewport(true);/* w w w.jav a 2 s .c o m*/ mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density); mTabStrip = new SlidingTabStrip(context); mTabStrip.setGravity(Gravity.CENTER_VERTICAL); addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); }
From source file:com.nearnotes.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mDbHelper = new NotesDbAdapter(this); // Create new custom database class for sqlite and pass the current context as a variable mDbHelper.open(); // Gets the writable database // enable ActionBar app icon to behave as action to toggle nav drawer LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.LEFT | Gravity.CENTER_VERTICAL); View customNav = getLayoutInflater().inflate(R.layout.edit_title, null); // layout which contains your button. getActionBar().setDisplayShowCustomEnabled(true); getActionBar().setCustomView(customNav, lp); getActionBar().setDisplayHomeAsUpEnabled(true); // getActionBar().setHomeButtonEnabled(true); // Start nav drawer mTitle = mDrawerTitle = getTitle();// www . j a va 2 s . c o m mMenuTitles = getResources().getStringArray(R.array.drawer_menu_array); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // set a custom shadow that overlays the main content when the drawer opens mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mMenuTitles)); // set up the drawer's list view with items and click listener mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); // ActionBarDrawerToggle ties together the the proper interactions between the sliding drawer and the action bar app icon mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } @Override public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; mDrawerLayout.setDrawerListener(mDrawerToggle); NoteList newFragment = new NoteList(); Bundle args = new Bundle(); args.putDouble("latitude", mLatitude); args.putDouble("longitude", mLongitude); newFragment.setArguments(args); FragmentTransaction transaction1 = getSupportFragmentManager().beginTransaction(); transaction1.replace(R.id.fragment_container, newFragment); // transaction1.addToBackStack(null); transaction1.commit(); //fetchAllNotes(); }