public static ViewOverlayPreJellybean getOverlay(ViewGroup sceneRoot) { if (sceneRoot != null) { ViewGroup group = sceneRoot; while (group.getId() != android.R.id.content && group.getParent() != null && group.getParent() instanceof ViewGroup) { group = (ViewGroup) group.getParent(); } for (int i = 0; i < group.getChildCount(); i++) { View child = group.getChildAt(i); if (child instanceof ViewOverlayPreJellybean) { return (ViewOverlayPreJellybean) child; } } final FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); params.gravity = Gravity.FILL; ViewOverlayPreJellybean viewOverlay = new ViewOverlayPreJellybean(sceneRoot.getContext()); group.addView(viewOverlay, params); return viewOverlay; } else { return null; } }
protected void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(0x7f030070); bundle = (RelativeLayout) findViewById(0x7f0a00be); mTimer = new Timer(); if (sSlot != null) { sSlot.setParameter("renderer.html.shouldUseDip", "true"); android.widget.RelativeLayout.LayoutParams layoutparams = new android.widget.RelativeLayout.LayoutParams(-1, -1); layoutparams.addRule(13); ViewGroup viewgroup = sSlot.getBase(); viewgroup.setLayoutParams(layoutparams); try { ((ViewGroup) viewgroup.getParent()).removeView(viewgroup); } catch (Exception exception) { } bundle.addView(viewgroup); sSlot.play(); mTimer.schedule(new HomeTask(), 5000L); return; } else { mTimer.schedule(new HomeTask(), 0L); return; } }
private void insertarTabs(ViewGroup container) { View padre = (View) container.getParent(); appBar = (AppBarLayout) padre.findViewById(R.id.appbar); pestanas = new TabLayout(getActivity()); pestanas.setTabTextColors(Color.parseColor("#FFFFFF"), Color.parseColor("#FFFFFF")); appBar.addView(pestanas); }
public void reconfigureViewHierarchy() { final DisplayMetrics dm = getResources().getDisplayMetrics(); final int widthPixels = dm.widthPixels; if (mDecorView == null) { return; } if (mDrawerContent != null) { removeView(mDrawerContent); } if (mDecorContent != null) { /* * Add the window/content (whatever it is at the time) back to its original parent. */ removeView(mDecorContent); mDecorContentParent.addView(mDecorContent); /* * Reset the window/content's OnClickListener/background color to default values as well */ mDecorContent.setOnClickListener(null); mDecorContent.setBackgroundColor(Color.TRANSPARENT); } if (mAdded) { mDecorContentParent.removeView(this); } if (mSlideTarget == SLIDE_TARGET_CONTENT) { mDecorContent = mContentTarget; mDecorContentParent = mContentTargetParent; } else if (mSlideTarget == SLIDE_TARGET_WINDOW) { mDecorContent = mWindowTarget; mDecorContentParent = mWindowTargetParent; } else { throw new IllegalArgumentException( "Slide target must be one of SLIDE_TARGET_CONTENT or SLIDE_TARGET_WINDOW."); } ((ViewGroup) mDecorContent.getParent()).removeView(mDecorContent); addView(mDrawerContent, new ViewGroup.LayoutParams(mDrawerMaxWidth, MATCH_PARENT)); addView(mDecorContent, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)); mDecorContentParent.addView(this); mAdded = true; /* Set background color of the content view (it shouldn't be transparent) */ mDecorContent.setBackgroundColor(mDecorContentBackgroundColor); /* Reset shadow bounds */ mShadowDrawable.setBounds(-mTouchTargetWidth / 6, 0, 0, dm.heightPixels); /* * Set an empty onClickListener on the Decor content parent to prevent any touch events * from escaping and passing through to the drawer even while it's closed. */ mDecorContent.setOnClickListener( new OnClickListener() { @Override public void onClick(View view) {} }); }
@Override public void setAdapter(Adapter adapter) { // Only once if (mEmptyViewResId != -1) { if (null != getParent()) { ViewGroup parentView = ((ViewGroup) getParent()); View tempEmptyView1 = parentView.findViewById(mEmptyViewResId); if (null != tempEmptyView1) { mEmptyView = tempEmptyView1; if (isKeepShowHeadOrFooter) parentView.removeView(tempEmptyView1); } else { ViewParent pParentView = parentView.getParent(); if (null != pParentView && pParentView instanceof ViewGroup) { View tempEmptyView2 = ((ViewGroup) pParentView).findViewById(mEmptyViewResId); if (null != tempEmptyView2) { mEmptyView = tempEmptyView2; if (isKeepShowHeadOrFooter) ((ViewGroup) pParentView).removeView(tempEmptyView2); } } } } mEmptyViewResId = -1; } else if (isKeepShowHeadOrFooter && null != mEmptyView) { ((ViewGroup) mEmptyView.getParent()).removeView(mEmptyView); } if (null == adapter) { if (null != mReqAdapter) { if (!isKeepShowHeadOrFooter) { mReqAdapter.unregisterAdapterDataObserver(mReqAdapterDataObserver); } mReqAdapter = null; mWrapFamiliarRecyclerViewAdapter = null; processEmptyView(); } return; } mReqAdapter = adapter; mWrapFamiliarRecyclerViewAdapter = new FamiliarWrapRecyclerViewAdapter( this, adapter, mHeaderView, mFooterView, mLayoutManagerType); mWrapFamiliarRecyclerViewAdapter.setOnItemClickListener(mTempOnItemClickListener); mWrapFamiliarRecyclerViewAdapter.setOnItemLongClickListener(mTempOnItemLongClickListener); mReqAdapter.registerAdapterDataObserver(mReqAdapterDataObserver); super.setAdapter(mWrapFamiliarRecyclerViewAdapter); processEmptyView(); }
private void removeBannerAd() { if (bannerAd != null) { bannerAd.setAdListener(null); ViewGroup bannerAdParent = (ViewGroup) bannerAd.getParent(); ViewGroup group = (ViewGroup) bannerAdParent.getParent(); group.removeView(bannerAdParent); bannerAd = null; listener.onDismissScreen(); } }
@Override protected void onDestroy() { super.onDestroy(); if (toast != null && toast.getParent() != null) { getWindowManager().removeViewImmediate(toast); } this.toast = null; this.progressDialog = null; if (subscription != null && !subscription.isUnsubscribed()) subscription.unsubscribe(); if (compositeSubscription.hasSubscriptions()) compositeSubscription.clear(); }
@Override public void onHideCustomView() { try { if (customView != null) { ViewParent viewparent = customView.getParent(); if (viewparent != null) ((ViewGroup) viewparent).removeView(customView); } mCustomViewCallback.onCustomViewHidden(); } catch (Exception e) { Log.e("WebViewActivity", "Can't remove custom view (video player)", e); } }
public View getUpperViewIn(View view, String listId) { ViewGroup p = (ViewGroup) view.getParent(); ViewGroup t = null; while (p != null) { LogEx.i(p.toString()); t = (ViewGroup) p.getParent(); if (t != null && t.getId() == this.getId(listId)) return p; p = t; } return null; }
public DrawerGarment(Activity activity, int drawerLayout) { super(activity); final DisplayMetrics dm = activity.getResources().getDisplayMetrics(); mTouchTargetWidth = Math.round( TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, TOUCH_TARGET_WIDTH_DIP, dm)); mShadowDrawable = getResources().getDrawable(R.drawable.decor_shadow); mScrollerHandler = new Handler(); mScroller = new Scroller(activity, new SmoothInterpolator()); /* Default to targeting the entire window (i.e., including the Action Bar) */ mSlideTarget = SLIDE_TARGET_WINDOW; mDecorView = (ViewGroup) activity.getWindow().getDecorView(); mWindowTarget = (ViewGroup) mDecorView.getChildAt(0); mWindowTargetParent = (ViewGroup) mWindowTarget.getParent(); mContentTarget = (ViewGroup) mDecorView.findViewById(android.R.id.content); mContentTargetParent = (ViewGroup) mContentTarget.getParent(); mDrawerContent = (ViewGroup) LayoutInflater.from(activity).inflate(drawerLayout, null); /* * Mutilate the view hierarchy and re-appropriate the slide target, * be it the entire window or just android.R.id.content, under * this DrawerGarment. */ reconfigureViewHierarchy(); /* * This currently causes lock-ups on 10" tablets (e.g., Xoom & Transformer), * should probably look into why this is happening. * if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { setLayerType(LAYER_TYPE_HARDWARE, null); } */ }
/** * Manage the ads visibility in the layout * * @param ad The view container where ads will be displayed * @param enabled true to enable ads, false to remove from layout. */ protected void manageAdView(ViewGroup adContainer, boolean enabled) { if (adContainer != null) { if (adManager != null) { adManager.destroy(); } if (enabled) { adManager = new BannerAdManager(this, adContainer); } else { ((ViewGroup) adContainer.getParent()).removeView(adContainer); } } }
private void updateAccountInfos(final SipProfile acc) { if (acc != null && acc.id != SipProfile.INVALID_ID) { setFirstViewVisibility(false); } else { if (firstView == null) { firstView = new AccountCreationFirstView(parent); ViewGroup globalContainer = (ViewGroup) settingsContainer.getParent(); firstView.setOnAccountCreationFirstViewListener(this); globalContainer.addView(firstView); } setFirstViewVisibility(true); } }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment // Because of the maps, we need to have the view inflated only once (viewpager, may call this // multiple times // so if this is the first time, ie myView is null, then do the setup, otherwise, "reset" the // view, by removing it // and return the already setup view. if (myView == null) { myView = inflater.inflate(R.layout.fragment_map, container, false); } else { ((ViewGroup) container.getParent()).removeView(myView); return myView; } // in a fragment This method is deprecated and can return a null map. // map = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).getMap(); // The new method here, will provide a non-null map. ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)) .getMapAsync( new OnMapReadyCallback() { @Override public void onMapReady(GoogleMap googleMap) { map = googleMap; // Zoom in, animating the camera. map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null); // Sets the map type to be "hybrid" map.setMapType(GoogleMap.MAP_TYPE_NORMAL); // normal map // map.setMapType(GoogleMap.MAP_TYPE_HYBRID); // allow user to use zoom controls (ie the + - buttons on the map. map.getUiSettings().setZoomControlsEnabled(true); map.setOnPolylineClickListener( new GoogleMap.OnPolylineClickListener() { @Override public void onPolylineClick(Polyline polyline) { Toast.makeText( getActivity(), getActivityString(polyline.getColor()), Toast.LENGTH_LONG) .show(); } }); } }); return myView; }
public void remove() { if (mHightLightView == null) return; ViewGroup parent = (ViewGroup) mHightLightView.getParent(); if (parent instanceof RelativeLayout || parent instanceof FrameLayout) { parent.removeView(mHightLightView); } else { parent.removeView(mHightLightView); View origin = parent.getChildAt(0); ViewGroup graParent = (ViewGroup) parent.getParent(); graParent.removeView(parent); graParent.addView(origin, parent.getLayoutParams()); } mHightLightView = null; }
private int[] findLocation(View v) { int row = 0, col = 0; ViewGroup parent = (ViewGroup) v.getParent(); // row contain for (int i = 0; i < parent.getChildCount(); i++) { if (v == parent.getChildAt(i)) { col = i; break; } } ViewGroup p_parent = (ViewGroup) parent.getParent(); // content contain for (int i = 0; i < p_parent.getChildCount(); i++) { if (parent == p_parent.getChildAt(i)) { row = i; break; } } int position[] = {row, col}; return position; }
public void onComplete(AVPlayer aVPlayer) { MRAIDAudioVideoController.this.setBusy(false); try { ViewGroup backGroundLayout = aVPlayer.getBackGroundLayout(); if (backGroundLayout != null) { ((ViewGroup) backGroundLayout.getParent()).removeView(aVPlayer.getBackGroundLayout()); } aVPlayer.setBackGroundLayout(null); } catch (Exception e) { Log.debug( Constants.RENDERING_LOG_TAG, "Problem removing the video framelayout or relativelayout depending on video startstyle", e); } synchronized (this) { if (MRAIDAudioVideoController.this.videoPlayer != null && aVPlayer .getPropertyID() .equalsIgnoreCase(MRAIDAudioVideoController.this.videoPlayer.getPropertyID())) { MRAIDAudioVideoController.this.videoPlayer = null; } } }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); Log.v(this.getClass().getCanonicalName(), "onCreateView MAP Fragment"); ((ViewGroup) container.getParent()).removeView(rootView); try { rootView = inflater.inflate(R.layout.maps_v2, container, false); Log.v(this.getClass().getCanonicalName(), "inflate OK MAP Fragment"); // getActivity().getFragmentManager().findFragmentById(id) oMapView = ((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.gmapv2)) .getMap(); /*SupportMapFragment mMapFragment = SupportMapFragment.newInstance(); FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction(); fragmentTransaction.add(R.id.gmapv2, mMapFragment); fragmentTransaction.commit(); oMapView= mMapFragment.getMap(); */ } catch (InflateException e) { /* map is already there, just return view as it is */ Log.e(this.getClass().getCanonicalName(), "InflateException"); e.printStackTrace(); } catch (Exception e) { // TODO: handle exception Log.e(this.getClass().getCanonicalName(), "Exception"); e.printStackTrace(); } return rootView; }
private ViewGroup generateLayout() { if (DEBUG) Log.d(TAG, "[generateLayout]"); // Apply data from current theme. TypedArray a = mActivity.getTheme().obtainStyledAttributes(R.styleable.SherlockTheme); mIsFloating = a.getBoolean(R.styleable.SherlockTheme_android_windowIsFloating, false); if (!a.hasValue(R.styleable.SherlockTheme_windowActionBar)) { throw new IllegalStateException( "You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative."); } if (a.getBoolean(R.styleable.SherlockTheme_windowNoTitle, false)) { requestFeature(Window.FEATURE_NO_TITLE); } else if (a.getBoolean(R.styleable.SherlockTheme_windowActionBar, false)) { // Don't allow an action bar if there is no title. requestFeature(Window.FEATURE_ACTION_BAR); } if (a.getBoolean(R.styleable.SherlockTheme_windowActionBarOverlay, false)) { requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY); } if (a.getBoolean(R.styleable.SherlockTheme_windowActionModeOverlay, false)) { requestFeature(Window.FEATURE_ACTION_MODE_OVERLAY); } a.recycle(); int layoutResource; if (!hasFeature(Window.FEATURE_NO_TITLE)) { if (mIsFloating) { // Trash original dialog LinearLayout mDecor = (ViewGroup) mDecor.getParent(); mDecor.removeAllViews(); layoutResource = R.layout.abs__dialog_title_holo; } else { if (hasFeature(Window.FEATURE_ACTION_BAR_OVERLAY)) { layoutResource = R.layout.abs__screen_action_bar_overlay; } else { layoutResource = R.layout.abs__screen_action_bar; } } } else if (hasFeature(Window.FEATURE_ACTION_MODE_OVERLAY) && !hasFeature(Window.FEATURE_NO_TITLE)) { layoutResource = R.layout.abs__screen_simple_overlay_action_mode; } else { layoutResource = R.layout.abs__screen_simple; } if (DEBUG) Log.d( TAG, "[generateLayout] using screen XML " + mActivity.getResources().getString(layoutResource)); View in = mActivity.getLayoutInflater().inflate(layoutResource, null); mDecor.addView(in, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)); ViewGroup contentParent = (ViewGroup) mDecor.findViewById(R.id.abs__content); if (contentParent == null) { throw new RuntimeException("Couldn't find content container view"); } // Make our new child the true content view (for fragments). VERY VOLATILE! mDecor.setId(View.NO_ID); contentParent.setId(android.R.id.content); if (hasFeature(Window.FEATURE_INDETERMINATE_PROGRESS)) { IcsProgressBar progress = getCircularProgressBar(false); if (progress != null) { progress.setIndeterminate(true); } } return contentParent; }
private boolean isSearchBoxVisible() { return mSearchBox.getParent() != null; }
/** * Returns how big this panel's view should be. This method should only be called when the view * has not been attached to a parent otherwise it will throw an illegal state. */ public Size measure() throws IllegalStateException { Preconditions.checkState(mContentView.getParent() == null); mContentView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); return new Size(mContentView.getMeasuredWidth(), mContentView.getMeasuredHeight()); }
private boolean isResultContainerVisible() { return mSearchResultContainer.getParent() != null; }
public boolean isDropEnabled() { final ViewGroup cellLayoutChildren = (ViewGroup) getParent(); final ViewGroup cellLayout = (ViewGroup) cellLayoutChildren.getParent(); final Workspace workspace = (Workspace) cellLayout.getParent(); return !workspace.isSmall(); }
/** Handles key events in the workspace hotseat (bottom of the screen). */ static boolean handleHotseatButtonKeyEvent(View v, int keyCode, KeyEvent e, int orientation) { final ViewGroup parent = (ViewGroup) v.getParent(); final ViewGroup launcher = (ViewGroup) parent.getParent(); final Workspace workspace = (Workspace) launcher.findViewById(R.id.workspace); final int buttonIndex = parent.indexOfChild(v); final int buttonCount = parent.getChildCount(); final int pageIndex = workspace.getCurrentPage(); // NOTE: currently we don't special case for the phone UI in different // orientations, even though the hotseat is on the side in landscape mode. This // is to ensure that accessibility consistency is maintained across rotations. final int action = e.getAction(); final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP); boolean wasHandled = false; switch (keyCode) { case KeyEvent.KEYCODE_DPAD_LEFT: if (handleKeyEvent) { // Select the previous button, otherwise snap to the previous page if (buttonIndex > 0) { parent.getChildAt(buttonIndex - 1).requestFocus(); } else { workspace.snapToPage(pageIndex - 1); } } wasHandled = true; break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (handleKeyEvent) { // Select the next button, otherwise snap to the next page if (buttonIndex < (buttonCount - 1)) { parent.getChildAt(buttonIndex + 1).requestFocus(); } else { workspace.snapToPage(pageIndex + 1); } } wasHandled = true; break; case KeyEvent.KEYCODE_DPAD_UP: if (handleKeyEvent) { // Select the first bubble text view in the current page of the workspace final CellLayout layout = (CellLayout) workspace.getChildAt(pageIndex); final ShortcutAndWidgetContainer children = layout.getShortcutsAndWidgets(); final View newIcon = getIconInDirection(layout, children, -1, 1); if (newIcon != null) { newIcon.requestFocus(); } else { workspace.requestFocus(); } } wasHandled = true; break; case KeyEvent.KEYCODE_DPAD_DOWN: // Do nothing wasHandled = true; break; default: break; } return wasHandled; }
private ViewGroup getViewForMessage(int num, boolean applyOffset) { if (NotificationsController.getInstance().popupMessages.size() == 1 && (num < 0 || num >= NotificationsController.getInstance().popupMessages.size())) { return null; } if (num == -1) { num = NotificationsController.getInstance().popupMessages.size() - 1; } else if (num == NotificationsController.getInstance().popupMessages.size()) { num = 0; } ViewGroup view; MessageObject messageObject = NotificationsController.getInstance().popupMessages.get(num); if (messageObject.type == 1 || messageObject.type == 4) { if (imageViews.size() > 0) { view = imageViews.get(0); imageViews.remove(0); } else { view = new FrameLayoutAnimationListener(this); view.addView(getLayoutInflater().inflate(R.layout.popup_image_layout, null)); view.setTag(2); view.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { openCurrentMessage(); } }); } TextView messageText = (TextView) view.findViewById(R.id.message_text); BackupImageView imageView = (BackupImageView) view.findViewById(R.id.message_image); imageView.setAspectFit(true); if (messageObject.type == 1) { TLRPC.PhotoSize currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize( messageObject.photoThumbs, AndroidUtilities.getPhotoSize()); TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 100); boolean photoSet = false; if (currentPhotoObject != null) { boolean photoExist = true; if (messageObject.type == 1) { File cacheFile = FileLoader.getPathToMessage(messageObject.messageOwner); if (!cacheFile.exists()) { photoExist = false; } } if (photoExist || MediaController.getInstance() .canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_PHOTO)) { imageView.setImage( currentPhotoObject.location, "100_100", thumb.location, currentPhotoObject.size); photoSet = true; } else { if (thumb != null) { imageView.setImage(thumb.location, null, (Drawable) null); photoSet = true; } } } if (!photoSet) { imageView.setVisibility(View.GONE); messageText.setVisibility(View.VISIBLE); messageText.setTextSize( TypedValue.COMPLEX_UNIT_SP, MessagesController.getInstance().fontSize); messageText.setText(messageObject.messageText); } else { imageView.setVisibility(View.VISIBLE); messageText.setVisibility(View.GONE); } } else if (messageObject.type == 4) { messageText.setVisibility(View.GONE); messageText.setText(messageObject.messageText); imageView.setVisibility(View.VISIBLE); double lat = messageObject.messageOwner.media.geo.lat; double lon = messageObject.messageOwner.media.geo._long; String currentUrl = String.format( Locale.US, "https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&zoom=13&size=100x100&maptype=roadmap&scale=%d&markers=color:red|size:big|%f,%f&sensor=false", lat, lon, Math.min(2, (int) Math.ceil(AndroidUtilities.density)), lat, lon); imageView.setImage(currentUrl, null, null); } } else if (messageObject.type == 2) { PopupAudioView cell; if (audioViews.size() > 0) { view = audioViews.get(0); audioViews.remove(0); cell = (PopupAudioView) view.findViewWithTag(300); } else { view = new FrameLayoutAnimationListener(this); view.addView(getLayoutInflater().inflate(R.layout.popup_audio_layout, null)); view.setTag(3); view.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { openCurrentMessage(); } }); ViewGroup audioContainer = (ViewGroup) view.findViewById(R.id.audio_container); cell = new PopupAudioView(this); cell.setTag(300); audioContainer.addView(cell); } cell.setMessageObject(messageObject); if (MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_AUDIO)) { cell.downloadAudioIfNeed(); } } else { if (textViews.size() > 0) { view = textViews.get(0); textViews.remove(0); } else { view = new FrameLayoutAnimationListener(this); view.addView(getLayoutInflater().inflate(R.layout.popup_text_layout, null)); view.setTag(1); View textContainer = view.findViewById(R.id.text_container); textContainer.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { openCurrentMessage(); } }); } TextView messageText = (TextView) view.findViewById(R.id.message_text); messageText.setTag(301); messageText.setTextSize( TypedValue.COMPLEX_UNIT_SP, MessagesController.getInstance().fontSize); messageText.setText(messageObject.messageText); } if (view.getParent() == null) { messageContainer.addView(view); } view.setVisibility(View.VISIBLE); if (applyOffset) { int widht = AndroidUtilities.displaySize.x - AndroidUtilities.dp(24); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams(); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT; layoutParams.width = widht; if (num == currentMessageNum) { layoutParams.leftMargin = 0; } else if (num == currentMessageNum - 1) { layoutParams.leftMargin = -widht; } else if (num == currentMessageNum + 1) { layoutParams.leftMargin = widht; } view.setLayoutParams(layoutParams); view.invalidate(); } return view; }