List of usage examples for android.view ViewGroup addView
public void addView(View child, int index, LayoutParams params)
From source file:android.support.v7.app.AlertController.java
private void setupContent(ViewGroup contentPanel) { mScrollView = (NestedScrollView) mWindow.findViewById(R.id.scrollView); mScrollView.setFocusable(false);//from w w w .java2 s. co m mScrollView.setNestedScrollingEnabled(false); // Special case for users that only want to display a String mMessageView = (TextView) contentPanel.findViewById(android.R.id.message); if (mMessageView == null) { return; } if (mMessage != null) { mMessageView.setText(mMessage); } else { mMessageView.setVisibility(View.GONE); mScrollView.removeView(mMessageView); if (mListView != null) { final ViewGroup scrollParent = (ViewGroup) mScrollView.getParent(); final int childIndex = scrollParent.indexOfChild(mScrollView); scrollParent.removeViewAt(childIndex); scrollParent.addView(mListView, childIndex, new LayoutParams(MATCH_PARENT, MATCH_PARENT)); } else { contentPanel.setVisibility(View.GONE); } } }
From source file:android.support.v7.app.AlertController.java
private void setupTitle(ViewGroup topPanel) { if (mCustomTitleView != null) { // Add the custom title view directly to the topPanel layout LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); topPanel.addView(mCustomTitleView, 0, lp); // Hide the title template View titleTemplate = mWindow.findViewById(R.id.title_template); titleTemplate.setVisibility(View.GONE); } else {//ww w .j a v a 2 s. com mIconView = (ImageView) mWindow.findViewById(android.R.id.icon); final boolean hasTextTitle = !TextUtils.isEmpty(mTitle); if (hasTextTitle) { // Display the title if a title is supplied, else hide it. mTitleView = (TextView) mWindow.findViewById(R.id.alertTitle); mTitleView.setText(mTitle); // Do this last so that if the user has supplied any icons we // use them instead of the default ones. If the user has // specified 0 then make it disappear. if (mIconId != 0) { mIconView.setImageResource(mIconId); } else if (mIcon != null) { mIconView.setImageDrawable(mIcon); } else { // Apply the padding from the icon to ensure the title is // aligned correctly. mTitleView.setPadding(mIconView.getPaddingLeft(), mIconView.getPaddingTop(), mIconView.getPaddingRight(), mIconView.getPaddingBottom()); mIconView.setVisibility(View.GONE); } } else { // Hide the title template final View titleTemplate = mWindow.findViewById(R.id.title_template); titleTemplate.setVisibility(View.GONE); mIconView.setVisibility(View.GONE); topPanel.setVisibility(View.GONE); } } }
From source file:com.me.harris.listviewitemanimations._01_activityAnim.ActivityAnimations.java
private void handleStatusBar() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { ViewGroup mContentView = (ViewGroup) findViewById(Window.ID_ANDROID_CONTENT); /* int statusBarHeight = getStatusBarHeight(); /*from ww w . j a v a2 s. com*/ View mChildView = mContentView.getChildAt(0); if (mChildView != null) { FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mChildView.getLayoutParams(); //? ChildView marginTop, ? if (lp != null && lp.topMargin < statusBarHeight && lp.height != statusBarHeight) { //? ViewCompat.setFitsSystemWindows(mChildView, false); lp.topMargin += statusBarHeight; mChildView.setLayoutParams(lp); } } View statusBarView = mContentView.getChildAt(0); if (statusBarView != null && statusBarView.getLayoutParams() != null && statusBarView.getLayoutParams().height == statusBarHeight) { //???? View statusBarView.setBackgroundColor(ContextCompat.getColor(this,R.color.colorPrimaryDark)); return; }*/ int statusBarHeight = getStatusBarHeight(); View statusBarView = new View(this); ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, statusBarHeight); statusBarView.setBackgroundColor(ContextCompat.getColor(this, R.color.colorPrimaryDark)); //? ContentView ? View mContentView.addView(statusBarView, 0, lp); } }
From source file:com.andryr.musicplayer.activities.EqualizerActivity.java
private void initSeekBars() { ViewGroup layout = (ViewGroup) findViewById(R.id.equalizer_layout); final short[] range = AudioEffects.getBandLevelRange(); LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, 0, 1); short bands = AudioEffects.getNumberOfBands(); for (short band = 0; band < bands; band++) { View v = getLayoutInflater().inflate(R.layout.equalizer_slider, layout, false); SeekBar seekBar = (SeekBar) v.findViewById(R.id.seek_bar); seekBar.setMax(range[1] - range[0]); seekBar.setTag(band);/*from w w w.j a v a 2s . co m*/ final TextView levelTextView = (TextView) v.findViewById(R.id.level); seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) { short band = (Short) seekBar.getTag(); short level = (short) (seekBar.getProgress() + range[0]); AudioEffects.setBandLevel(band, level); levelTextView.setText((level > 0 ? "+" : "") + level / 100 + "dB"); mSpinner.setSelection(0); } } }); layout.addView(v, band, lp); } }
From source file:com.cognizant.trumobi.PersonaLauncher.java
public void showPreviews(final View anchor, int start, int end) { if (mWorkspace != null && mWorkspace.getChildCount() > 0) { if (newPreviews) { showingPreviews = true;//from w w w. j a va2 s. c o m hideDesktop(true); mWorkspace.lock(); mWorkspace.openSense(true); } else { // check first if it's already open final PopupWindow window = (PopupWindow) anchor.getTag(R.id.TAG_PREVIEW); if (window != null) return; Resources resources = getResources(); PersonaWorkspace personaWorkspace = mWorkspace; PersonaCellLayout cell = ((PersonaCellLayout) personaWorkspace.getChildAt(start)); float max; ViewGroup preview; max = personaWorkspace.getChildCount(); preview = new LinearLayout(this); Rect r = new Rect(); // ADW: seems sometimes this throws an out of memory error.... // so... try { resources.getDrawable(R.drawable.pr_preview_background).getPadding(r); } catch (OutOfMemoryError e) { } int extraW = (int) ((r.left + r.right) * max); int extraH = r.top + r.bottom; int aW = cell.getWidth() - extraW; float w = aW / max; int width = cell.getWidth(); int height = cell.getHeight(); // width -= (x + cell.getRightPadding()); // height -= (y + cell.getBottomPadding()); if (width != 0 && height != 0) { showingPreviews = true; float scale = w / width; int count = end - start; final float sWidth = width * scale; float sHeight = height * scale; PreviewTouchHandler handler = new PreviewTouchHandler(anchor); ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count); for (int i = start; i < end; i++) { ImageView image = new ImageView(this); cell = (PersonaCellLayout) personaWorkspace.getChildAt(i); Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight, Bitmap.Config.ARGB_8888); cell.setDrawingCacheEnabled(false); Canvas c = new Canvas(bitmap); c.scale(scale, scale); c.translate(-cell.getLeftPadding(), -cell.getTopPadding()); cell.dispatchDraw(c); image.setBackgroundDrawable(resources.getDrawable(R.drawable.pr_preview_background)); image.setImageBitmap(bitmap); image.setTag(i); image.setOnClickListener(handler); image.setOnFocusChangeListener(handler); image.setFocusable(true); if (i == mWorkspace.getCurrentScreen()) image.requestFocus(); preview.addView(image, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); bitmaps.add(bitmap); } PopupWindow p = new PopupWindow(this); p.setContentView(preview); p.setWidth((int) (sWidth * count + extraW)); p.setHeight((int) (sHeight + extraH)); p.setAnimationStyle(R.style.AnimationPreview); p.setOutsideTouchable(true); p.setFocusable(true); p.setBackgroundDrawable(new ColorDrawable(0)); p.showAsDropDown(anchor, 0, 0); p.setOnDismissListener(new PopupWindow.OnDismissListener() { public void onDismiss() { dismissPreview(anchor); } }); anchor.setTag(R.id.TAG_PREVIEW, p); anchor.setTag(R.id.workspace, preview); anchor.setTag(R.id.icon, bitmaps); } } } }