Example usage for android.view ViewGroup getLayoutParams

List of usage examples for android.view ViewGroup getLayoutParams

Introduction

In this page you can find the example usage for android.view ViewGroup getLayoutParams.

Prototype

@ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_")
public ViewGroup.LayoutParams getLayoutParams() 

Source Link

Document

Get the LayoutParams associated with this view.

Usage

From source file:Main.java

public static void setViewGroupHeight(ViewGroup vg, int height) {
    ViewGroup.LayoutParams lp = vg.getLayoutParams();
    lp.height = height;/*from www  . j  a  v  a 2  s.co m*/
    vg.setLayoutParams(lp);
}

From source file:Main.java

public static void expand(final ViewGroup v) {
    v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final int targetHeight = v.getMeasuredHeight();

    // Older versions of android (pre API 21) cancel animations for views with a height of 0.
    v.getLayoutParams().height = 1;
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation() {
        @Override/*  w  w w. ja v  a 2 s. co m*/
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1 ? ViewGroup.LayoutParams.WRAP_CONTENT
                    : (int) (targetHeight * interpolatedTime);
            v.setAlpha(interpolatedTime);
            v.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    // 1dp/ms
    a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}

From source file:Main.java

public static void collapse(final ViewGroup v) {
    final int initialHeight = v.getMeasuredHeight();

    Animation a = new Animation() {
        @Override//from   w  ww.ja v  a2s  .  c  o m
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if (interpolatedTime == 1) {
                v.setVisibility(View.GONE);
            } else {
                v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime);
                v.setAlpha(1 - interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}

From source file:Main.java

private static void unwrapView(ViewGroup wrapper) {
    final int childCount = wrapper.getChildCount();
    View[] childViews = new View[childCount];

    ViewGroup parent = (ViewGroup) wrapper.getParent();

    if (parent != null) {
        parent.removeView(wrapper);//from  w  ww  .  j av  a  2  s. c  o  m
    }

    for (int i = 0; i < childCount; i++) {
        childViews[i] = wrapper.getChildAt(i);
    }

    // If there was just one wrapper reuse the wrapper layout
    // params to ensure correct type for parent
    if (childCount == 1) {
        ViewGroup.LayoutParams wrapperParams = wrapper.getLayoutParams();
        if (wrapperParams != null) {
            childViews[0].setLayoutParams(wrapperParams);
        }
    }

    for (int i = 0; i < childCount; i++) {
        final View childView = childViews[i];

        wrapper.removeView(childView);
        if (parent != null) {
            parent.addView(childView);
        }
    }
}

From source file:info.papdt.blacklight.support.Utility.java

public static View addActionViewToCustom(View v, ViewGroup custom) {
    if (v != null) {
        ViewGroup parent = (ViewGroup) v.getParent();
        parent.removeView(v);//from  www  .  ja v  a2  s  . co m
        parent.setVisibility(View.GONE);
        ViewGroup.LayoutParams params = parent.getLayoutParams();
        params.width = 0;
        params.height = 0;
        parent.setLayoutParams(params);
        custom.addView(v);
    }

    return v;
}

From source file:com.swisscom.safeconnect.activity.TutorialActivity.java

protected void setUpContent(final int width) {
    final String[] pageDescriptions = getResources().getStringArray(R.array.tutorial_page_descriptions);

    for (int i = 0; i < viewPager.getAdapter().getCount(); i++) {
        ViewGroup viewGroup = (ViewGroup) viewPager.getAdapter().instantiateItem(null, i);
        viewGroup.getLayoutParams().width = width;

        if (i < pageDescriptions.length) {
            TextView descriptionTextView = (TextView) viewGroup.findViewById(R.id.descriptionTextView);
            descriptionTextView.setText(pageDescriptions[i]);
        }//from w w  w.j  ava  2s. co  m
    }
}

From source file:org.sufficientlysecure.keychain.ui.DrawerActivity.java

protected void setupDrawerNavigation(Bundle savedInstanceState) {
    mDrawerTitle = getString(R.string.app_name);
    mDrawerLayout = (FixedDrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    ViewGroup viewGroup = (ViewGroup) findViewById(R.id.content_frame);
    int leftMarginLoaded = ((ViewGroup.MarginLayoutParams) viewGroup.getLayoutParams()).leftMargin;
    int leftMarginInTablets = (int) getResources().getDimension(R.dimen.drawer_size);
    int errorInMarginAllowed = 5;

    // if the left margin of the loaded layout is close to the
    // one used in tablets then set drawer as open and locked
    if (Math.abs(leftMarginLoaded - leftMarginInTablets) < errorInMarginAllowed) {
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, mDrawerList);
        mDrawerLayout.setScrimColor(Color.TRANSPARENT);
        mIsDrawerLocked = true;/*from   w  ww.j  a  v  a  2  s  .  c  o  m*/
    } else {
        // set a custom shadow that overlays the main content when the drawer opens
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
        mIsDrawerLocked = false;
    }

    NavItem mItemIconTexts[] = new NavItem[] { new NavItem("fa-user", getString(R.string.nav_keys)),
            new NavItem("fa-lock", getString(R.string.nav_encrypt)),
            new NavItem("fa-unlock", getString(R.string.nav_decrypt)),
            new NavItem("fa-android", getString(R.string.nav_apps)) };

    mDrawerList.setAdapter(new NavigationDrawerAdapter(this, R.layout.drawer_list_item, mItemIconTexts));

    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // enable ActionBar app icon to behave as action to toggle nav drawer
    // if the drawer is not locked
    if (!mIsDrawerLocked) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
    }

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);

            callIntentForDrawerItem(mSelectedItem);
        }

        public void onDrawerOpened(View drawerView) {
            mTitle = getSupportActionBar().getTitle();
            getSupportActionBar().setTitle(mDrawerTitle);
            // creates call to onPrepareOptionsMenu()
            supportInvalidateOptionsMenu();
        }
    };

    if (!mIsDrawerLocked) {
        mDrawerLayout.setDrawerListener(mDrawerToggle);
    } else {
        // If the drawer is locked open make it un-focusable
        // so that it doesn't consume all the Back button presses
        mDrawerLayout.setFocusableInTouchMode(false);
    }
}

From source file:org.thialfihar.android.apg.ui.DrawerActivity.java

protected void setupDrawerNavigation(Bundle savedInstanceState) {
    mDrawerTitle = getString(R.string.app_name);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);
    ViewGroup viewGroup = (ViewGroup) findViewById(R.id.content_frame);
    int leftMarginLoaded = ((ViewGroup.MarginLayoutParams) viewGroup.getLayoutParams()).leftMargin;
    int leftMarginInTablets = (int) getResources().getDimension(R.dimen.drawer_size);
    int errorInMarginAllowed = 5;

    // if the left margin of the loaded layout is close to the
    // one used in tablets then set drawer as open and locked
    if (Math.abs(leftMarginLoaded - leftMarginInTablets) < errorInMarginAllowed) {
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, mDrawerList);
        mDrawerLayout.setScrimColor(Color.TRANSPARENT);
        mIsDrawerLocked = true;/*w ww.jav a  2  s .c  om*/
    } else {
        // set a custom shadow that overlays the main content when the drawer opens
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
        mIsDrawerLocked = false;
    }

    NavItem mItemIconTexts[] = new NavItem[] { new NavItem("fa-user", getString(R.string.nav_contacts)),
            new NavItem("fa-lock", getString(R.string.nav_encrypt)),
            new NavItem("fa-unlock", getString(R.string.nav_decrypt)),
            new NavItem("fa-download", getString(R.string.nav_import)),
            new NavItem("fa-android", getString(R.string.nav_apps)) };

    mDrawerList.setAdapter(new NavigationDrawerAdapter(this, R.layout.drawer_list_item, mItemIconTexts));

    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // enable ActionBar app icon to behave as action to toggle nav drawer
    // if the drawer is not locked
    if (!mIsDrawerLocked) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);
    }

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);

            callIntentForDrawerItem(mSelectedItem);
        }

        public void onDrawerOpened(View drawerView) {
            mTitle = getSupportActionBar().getTitle();
            getSupportActionBar().setTitle(mDrawerTitle);
            // creates call to onPrepareOptionsMenu()
            supportInvalidateOptionsMenu();
        }
    };

    if (!mIsDrawerLocked) {
        mDrawerLayout.setDrawerListener(mDrawerToggle);
    } else {
        // If the drawer is locked open make it un-focusable
        // so that it doesn't consume all the Back button presses
        mDrawerLayout.setFocusableInTouchMode(false);
    }
    // if (savedInstanceState == null) {
    // selectItem(0);
    // }
}

From source file:org.zywx.wbpalmstar.plugin.uexiconlist.EUExIconList.java

/**
 * ??IconList view? ??/*from ww w. j  av a  2  s.com*/
 * 
 */
private void resetFrame() {
    ((Activity) mContext).runOnUiThread(new Runnable() {

        @Override
        public void run() {
            if (mgr == null) {
                mgr = new LocalActivityManager((Activity) mContext, false);
                mgr.dispatchCreate(null);
            }
            Activity activity = mgr.getActivity(IconListActivity.TAG);
            if (activity != null) {
                ViewGroup subView = (ViewGroup) activity.getWindow().getDecorView();
                if (IconListOption.isFollowWebRoll()) {
                    AbsoluteLayout.LayoutParams lParams = (LayoutParams) subView.getLayoutParams();
                    lParams.width = (int) UIConfig.getScaleWidth();
                    lParams.height = (int) UIConfig.getScaleHight();
                    lParams.x = (int) UIConfig.getScaleX();
                    lParams.y = (int) UIConfig.getScaleY();
                    //                        AbsoluteLayout.LayoutParams lp = new AbsoluteLayout.LayoutParams(
                    //                                (int) UIConfig.getScaleWidth(),
                    //                                (int) UIConfig.getScaleHight(),
                    //                                (int) UIConfig.getScaleX(),
                    //                                (int) UIConfig.getScaleY());
                    subView.setLayoutParams(lParams);
                } else {
                    FrameLayout.LayoutParams lParams = (FrameLayout.LayoutParams) subView.getLayoutParams();
                    lParams.width = (int) UIConfig.getScaleWidth();
                    lParams.height = (int) UIConfig.getScaleHight();
                    lParams.leftMargin = (int) UIConfig.getScaleX();
                    lParams.topMargin = (int) UIConfig.getScaleY();
                    // FrameLayout.LayoutParams lp = new
                    // FrameLayout.LayoutParams(
                    // (int) UIConfig.getScaleWidth(),
                    // (int) UIConfig.getScaleHight());
                    // lp.leftMargin = (int) UIConfig.getScaleX();
                    // lp.topMargin = (int) UIConfig.getScaleY();
                    subView.setLayoutParams(lParams);
                }
                subView.invalidate();
                mEuExIconListHandler.send2Callback(WHAT_RESET_FRAME, null);
            }
        }
    });
}

From source file:mobi.cangol.mobile.navigation.DrawerMenuLayout.java

private void fitDecorChild(View view) {
    ViewGroup contentView = (ViewGroup) view.findViewById(R.id.actionbar_content_view);
    if (contentView != null) {
        ViewGroup decorChild = (ViewGroup) contentView.getChildAt(0);
        if (decorChild != null) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                WindowManager manager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
                FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) decorChild.getLayoutParams();
                switch (manager.getDefaultDisplay().getRotation()) {
                case Surface.ROTATION_90:
                    layoutParams.rightMargin = 0;
                    break;
                case Surface.ROTATION_180:
                    layoutParams.topMargin = 0;
                    break;
                case Surface.ROTATION_270:
                    layoutParams.leftMargin = 0;
                    break;
                default:
                    layoutParams.bottomMargin = 0;
                }/*from w w w.j a  v  a  2s  .c o  m*/
                decorChild.setLayoutParams(layoutParams);
            }
        }
    }
}