List of usage examples for android.view ViewGroup getLayoutParams
@ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") public ViewGroup.LayoutParams getLayoutParams()
From source file:com.android.yijiang.kzx.widget.tab.PagerSlidingTabStrip.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { ViewGroup tabViewGroup = getTabsLayout(); // // w w w . ja v a2 s. co m if (tabViewGroup == null || tabViewGroup.getChildCount() <= 0) { super.onLayout(changed, l, t, r, b); return; } int viewWidth = r - l; // Item if ((measure(tabViewGroup).getMeasuredWidth() < viewWidth) && allowWidthFull) { // ?tabViewGroup?? viewWidth -= tabViewGroup.getPaddingLeft(); viewWidth -= tabViewGroup.getPaddingRight(); if (tabViewGroup.getLayoutParams() instanceof MarginLayoutParams) { MarginLayoutParams tabsLayoutParams = (MarginLayoutParams) tabViewGroup.getLayoutParams(); viewWidth -= tabsLayoutParams.leftMargin; viewWidth -= tabsLayoutParams.rightMargin; } // ??Tab? View tabView; for (int w = 0; w < tabViewGroup.getChildCount(); w++) { tabView = tabViewGroup.getChildAt(w); if (tabView.getLayoutParams() instanceof MarginLayoutParams) { MarginLayoutParams marginLayoutParams = (MarginLayoutParams) tabView.getLayoutParams(); viewWidth -= marginLayoutParams.leftMargin; viewWidth -= marginLayoutParams.rightMargin; } } // ? int averageWidth = viewWidth / tabViewGroup.getChildCount(); int bigTabCount = 0; // ?tab??? for (int w = 0; w < tabViewGroup.getChildCount(); w++) { tabView = tabViewGroup.getChildAt(w); // ???? if (tabView != null && tabView.getMeasuredWidth() > averageWidth) { viewWidth -= tabView.getMeasuredWidth(); bigTabCount++; } } // ? averageWidth = viewWidth / (tabViewGroup.getChildCount() - bigTabCount); // ??Item for (int w = 0; w < tabViewGroup.getChildCount(); w++) { //????? tabView = tabViewGroup.getChildAt(w); if (tabView != null) { ViewGroup.LayoutParams layoutParams = tabView.getLayoutParams(); if (layoutParams != null) { layoutParams.width = tabView.getMeasuredWidth() < averageWidth ? averageWidth : tabView.getMeasuredWidth(); tabView.setLayoutParams(layoutParams); measure(tabView); } } } measure(tabViewGroup); } // ????? currentPosition = viewPager != null ? viewPager.getCurrentItem() : 0; scrollToChild(currentPosition, 0); //?? selectedTab(currentPosition); //?TAB //?tab?Pager for (int w = 0; w < tabViewGroup.getChildCount(); w++) { View itemView = tabViewGroup.getChildAt(w); itemView.setTag(w); itemView.setOnClickListener(this); } super.onLayout(changed, l, t, r, b); }
From source file:com.mobicage.rogerthat.plugins.friends.ServiceActionMenuActivity.java
@Override protected void onServiceBound() { L.d("ServiceActionMenuActivity onServiceBound()"); final Typeface faTypeFace = Typeface.createFromAsset(getAssets(), "FontAwesome.ttf"); final int defaultFirstRowTextColor = Color.parseColor("#646464"); final FriendsPlugin friendsPlugin = mService.getPlugin(FriendsPlugin.class); final ServiceMenu menu = friendsPlugin.getStore().getMenu(email, page); TableLayout menu_table = (TableLayout) findViewById(R.id.menu_table); int tableWidth = menu_table.getWidth(); for (int x = 0; x < 4; x++) { for (int y = 0; y < 3; y++) { android.view.ViewGroup cellLayout = (android.view.ViewGroup) findViewById( getResources().getIdentifier("menu_" + x + "x" + y, "id", getPackageName())); android.view.ViewGroup.LayoutParams lp = cellLayout.getLayoutParams(); lp.width = tableWidth / 4;//from w w w . ja v a2s .co m cellLayout.setLayoutParams(lp); Cell cell = new Cell(); cell.icon = (ImageView) cellLayout.findViewById(R.id.icon); cell.faIcon = (TextView) cellLayout.findViewById(R.id.fa_icon); cell.label = (TextView) cellLayout.findViewById(R.id.label); cells[x][y] = cell; if (y == 0) { cell.icon.setVisibility(View.GONE); cell.faIcon.setTypeface(faTypeFace); cell.faIcon.setTextColor(defaultFirstRowTextColor); switch (x) { case 0: cell.faIcon.setVisibility(View.VISIBLE); cell.faIcon.setText(R.string.fa_info); break; case 1: cell.faIcon.setVisibility(View.VISIBLE); cell.faIcon.setText(R.string.fa_envelope); break; case 2: cell.faIcon.setVisibility(View.INVISIBLE); cell.faIcon.setText(R.string.fa_phone); break; case 3: cell.faIcon.setVisibility(View.INVISIBLE); cell.faIcon .setText(CloudConstants.isYSAAA() ? R.string.fa_qrcode : R.string.fa_thumbs_o_up); break; default: break; } } } } for (int y = 0; y < 3; y++) { TableRow row = (TableRow) findViewById(getResources().getIdentifier("row" + y, "id", getPackageName())); tableRows[y] = row; } clearScreen(); populateScreen(menu); IntentFilter filter = new IntentFilter(FriendsPlugin.FRIEND_UPDATE_INTENT); filter.addAction(FriendsPlugin.FRIEND_REMOVED_INTENT); filter.addAction(FriendsPlugin.FRIEND_MARKED_FOR_REMOVAL_INTENT); filter.addAction(MessagingPlugin.NEW_MESSAGE_RECEIVED_INTENT); filter.addAction(MessagingPlugin.MESSAGE_PROCESSED_INTENT); filter.addAction(MessagingPlugin.MESSAGE_LOCKED_INTENT); filter.addAction(MessagingPlugin.MESSAGE_DIRTY_CLEANED_INTENT); filter.addAction(MessagingPlugin.THREAD_DELETED_INTENT); filter.addAction(MessagingPlugin.THREAD_RECOVERED_INTENT); filter.addAction(BrandingMgr.SERVICE_BRANDING_AVAILABLE_INTENT); filter.addAction(BrandingMgr.GENERIC_BRANDING_AVAILABLE_INTENT); filter.addAction(MessagingPlugin.MESSAGE_JSMFR_ERROR); registerReceiver(mBroadcastReceiver, filter); findViewById(R.id.navigation_bar_home_button).setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { Intent i = new Intent(ServiceActionMenuActivity.this, HomeActivity.class); i.setFlags(MainActivity.FLAG_CLEAR_STACK); startActivity(i); finish(); } }); }
From source file:gr.plushost.prototypeapp.widgets.LabelView.java
public void remove() { if (getParent() == null || _labelViewContainerID == -1) { return;/*w w w. j a v a2 s .com*/ } ViewGroup frameContainer = (ViewGroup) getParent(); assert (frameContainer.getChildCount() == 2); View target = frameContainer.getChildAt(0); ViewGroup parentContainer = (ViewGroup) frameContainer.getParent(); int groupIndex = parentContainer.indexOfChild(frameContainer); if (frameContainer.getParent() instanceof RelativeLayout) { for (int i = 0; i < parentContainer.getChildCount(); i++) { if (i == groupIndex) { continue; } View view = parentContainer.getChildAt(i); RelativeLayout.LayoutParams para = (RelativeLayout.LayoutParams) view.getLayoutParams(); for (int j = 0; j < para.getRules().length; j++) { if (para.getRules()[j] == _labelViewContainerID) { para.getRules()[j] = target.getId(); } } view.setLayoutParams(para); } } ViewGroup.LayoutParams frameLayoutParam = frameContainer.getLayoutParams(); target.setLayoutParams(frameLayoutParam); parentContainer.removeViewAt(groupIndex); frameContainer.removeView(target); frameContainer.removeView(this); parentContainer.addView(target, groupIndex); _labelViewContainerID = -1; }
From source file:com.tomdignan.jiffymonitor.ChartFragment.java
/** {@inheritDoc} */ @Override/*from ww w .j a v a2s . c o m*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // requires a bundle with full arguments. Bundle args = getArguments(); long t1 = System.currentTimeMillis(); Loggy.d(TAG, "checking args time=%l", System.currentTimeMillis()); if (args == null || !args.containsKey(PARAM_HEIGHT) || !args.containsKey(PARAM_WIDTH) || !args.containsKey(PARAM_STROKE_WIDTH) || !args.containsKey(PARAM_ANTI_ALIAS) || !args.containsKey(PARAM_FG_COLOR) || !args.containsKey(PARAM_BG_COLOR) || !args.containsKey(PARAM_BG_DISABLED_COLOR) || !args.containsKey(PARAM_TEXT_COLOR) || !args.containsKey(PARAM_TEXT_SIZE) || !args.containsKey(PARAM_GRID_COLOR) || !args.containsKey(PARAM_GRID_THICKNESS)) { throw new IllegalStateException("CircularChartFragment requires bundle for PARAM_'s"); } Loggy.d(TAG, "checking args diff=%l", System.currentTimeMillis() - t1); ViewGroup.LayoutParams params = container.getLayoutParams(); params.height = args.getInt(PARAM_HEIGHT); params.width = args.getInt(PARAM_WIDTH); this.chartView = new CircularChartView(getActivity(), args); this.bgEnabledColor = args.getInt(PARAM_BG_COLOR); this.bgDisabledColor = args.getInt(PARAM_BG_DISABLED_COLOR); this.chartView.setBackgroundColor(bgEnabledColor); this.chartView.setLayoutParams(params); return this.chartView; }
From source file:android.car.ui.provider.CarDrawerLayout.java
/** * Open the drawer view by animating it into view. *//*from w w w. j a va 2s .co m*/ public void openDrawer() { ViewGroup drawerView = (ViewGroup) findDrawerView(); mStartedOpen = false; if (hasWindowFocus()) { int left; LayoutParams drawerLp = (LayoutParams) drawerView.getLayoutParams(); if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) { left = drawerLp.getMarginStart(); } else { left = drawerLp.getMarginStart() + getWidth() - drawerView.getWidth(); } mDragger.smoothSlideViewTo(drawerView, left, drawerView.getTop()); dispatchOnDrawerOpening(drawerView); } else { final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams(); lp.onScreen = 1.f; dispatchOnDrawerOpened(drawerView); } ViewGroup contentView = (ViewGroup) findContentView(); contentView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); drawerView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); View focusable = drawerView.getChildAt(0); if (focusable != null) { focusable.requestFocus(); } invalidate(); }
From source file:com.grottworkshop.gwsmaterialviewpagerreg.MaterialViewPager.java
@Override protected void onFinishInflate() { super.onFinishInflate(); //add @layout/material_view_pager_layout as child, containing all the MaterialViewPager views addView(LayoutInflater.from(getContext()).inflate(R.layout.material_view_pager_layout, this, false)); headerBackgroundContainer = (ViewGroup) findViewById(R.id.headerBackgroundContainer); pagerTitleStripContainer = (ViewGroup) findViewById(R.id.pagerTitleStripContainer); /*//from www .j a v a 2 s. c om the layout containing logo default : empty with viewpager_logo you can set your own layout */ ViewGroup logoContainer = (ViewGroup) findViewById(R.id.logoContainer); mToolbar = (Toolbar) findViewById(R.id.toolbar); mViewPager = (ViewPager) findViewById(R.id.viewPager); mViewPager.addOnPageChangeListener(this); //inflate subviews defined in attributes if (settings.headerLayoutId != -1) { headerBackgroundContainer.addView(LayoutInflater.from(getContext()).inflate(settings.headerLayoutId, headerBackgroundContainer, false)); } if (isInEditMode()) { //preview titlestrip //add fake tabs on edit mode settings.pagerTitleStripId = R.layout.tools_material_view_pager_pagertitlestrip; } if (settings.pagerTitleStripId != -1) { pagerTitleStripContainer.addView(LayoutInflater.from(getContext()).inflate(settings.pagerTitleStripId, pagerTitleStripContainer, false)); } if (settings.logoLayoutId != -1) { logoContainer.addView( LayoutInflater.from(getContext()).inflate(settings.logoLayoutId, logoContainer, false)); if (settings.logoMarginTop != 0) { RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) logoContainer .getLayoutParams(); layoutParams.setMargins(0, settings.logoMarginTop, 0, 0); logoContainer.setLayoutParams(layoutParams); } } headerBackground = findViewById(R.id.headerBackground); toolbarLayoutBackground = findViewById(R.id.toolbar_layout_background); initialiseHeights(); //construct the materialViewPagerHeader with subviews if (!isInEditMode()) { materialViewPagerHeader = MaterialViewPagerHeader.withToolbar(mToolbar) .withToolbarLayoutBackground(toolbarLayoutBackground) .withPagerSlidingTabStrip(pagerTitleStripContainer).withHeaderBackground(headerBackground) .withStatusBackground(findViewById(R.id.statusBackground)).withLogo(logoContainer); //and construct the MaterialViewPagerAnimator //attach it to the activity to enable MaterialViewPagerHeaderView.setMaterialHeight(); MaterialViewPagerHelper.register(getContext(), new MaterialViewPagerAnimator(this)); } else { //if in edit mode, add fake cardsviews View sample = LayoutInflater.from(getContext()).inflate(R.layout.tools_list_items, pagerTitleStripContainer, false); FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) sample.getLayoutParams(); int marginTop = Math.round(Utils.dpToPx(settings.headerHeight + 10, getContext())); params.setMargins(0, marginTop, 0, 0); super.setLayoutParams(params); addView(sample); } }
From source file:android.car.ui.provider.CarDrawerLayout.java
/** * Close the specified drawer view by animating it into view. *//*from ww w . j a va2 s . c o m*/ public void closeDrawer() { ViewGroup drawerView = (ViewGroup) findDrawerView(); if (!isDrawerView(drawerView)) { throw new IllegalArgumentException("View " + drawerView + " is not a sliding drawer"); } mStartedOpen = true; // Don't trigger the close drawer animation if drawer is not open. if (hasWindowFocus() && isDrawerOpen()) { int left; LayoutParams drawerLp = (LayoutParams) drawerView.getLayoutParams(); if (checkDrawerViewAbsoluteGravity(drawerView, Gravity.LEFT)) { left = drawerLp.getMarginStart() - drawerView.getWidth(); } else { left = drawerLp.getMarginStart() + getWidth(); } mDragger.smoothSlideViewTo(drawerView, left, drawerView.getTop()); dispatchOnDrawerClosing(drawerView); } else { final LayoutParams lp = (LayoutParams) drawerView.getLayoutParams(); lp.onScreen = 0.f; dispatchOnDrawerClosed(drawerView); } ViewGroup contentView = (ViewGroup) findContentView(); drawerView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); contentView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); if (!isInTouchMode()) { List<View> focusables = contentView.getFocusables(FOCUS_DOWN); if (focusables.size() > 0) { View candidate = focusables.get(0); candidate.requestFocus(); } } invalidate(); }
From source file:com.taobao.weex.ui.component.WXVContainer.java
/******************************** * end hook Activity life cycle callback ********************************************************/ public @Nullable View getBoxShadowHost(boolean isClear) { if (isClear) { // Return existed host if want clear shadow return mBoxShadowHost; }/*from w w w .j a v a 2 s . c o m*/ ViewGroup hostView = getHostView(); if (hostView == null) { return null; } try { String type = getComponentType(); if (WXBasicComponentType.DIV.equals(type)) { WXLogUtils.d("BoxShadow", "Draw box-shadow with BoxShadowHost on div: " + toString()); if (mBoxShadowHost == null) { mBoxShadowHost = new BoxShadowHost(getContext()); WXViewUtils.setBackGround(mBoxShadowHost, null, this); CSSShorthand padding = this.getPadding(); CSSShorthand border = this.getBorder(); int left = (int) (padding.get(CSSShorthand.EDGE.LEFT) + border.get(CSSShorthand.EDGE.LEFT)); int top = (int) (padding.get(CSSShorthand.EDGE.TOP) + border.get(CSSShorthand.EDGE.TOP)); int right = (int) (padding.get(CSSShorthand.EDGE.RIGHT) + border.get(CSSShorthand.EDGE.RIGHT)); int bottom = (int) (padding.get(CSSShorthand.EDGE.BOTTOM) + border.get(CSSShorthand.EDGE.BOTTOM)); ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams( hostView.getLayoutParams()); layoutParams.setMargins(-left, -top, -right, -bottom); mBoxShadowHost.setLayoutParams(layoutParams); hostView.addView(mBoxShadowHost); } hostView.removeView(mBoxShadowHost); hostView.addView(mBoxShadowHost); return mBoxShadowHost; } } catch (Throwable t) { WXLogUtils.w("BoxShadow", t); } return hostView; }
From source file:android.support.v7.app.AlertController.java
private void setupCustomContent(ViewGroup customPanel) { final View customView; if (mView != null) { customView = mView;/*from w ww . ja va 2s. com*/ } else if (mViewLayoutResId != 0) { final LayoutInflater inflater = LayoutInflater.from(mContext); customView = inflater.inflate(mViewLayoutResId, customPanel, false); } else { customView = null; } final boolean hasCustomView = customView != null; if (!hasCustomView || !canTextInput(customView)) { mWindow.setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); } if (hasCustomView) { final FrameLayout custom = (FrameLayout) mWindow.findViewById(R.id.custom); custom.addView(customView, new LayoutParams(MATCH_PARENT, MATCH_PARENT)); if (mViewSpacingSpecified) { custom.setPadding(mViewSpacingLeft, mViewSpacingTop, mViewSpacingRight, mViewSpacingBottom); } if (mListView != null) { ((LinearLayout.LayoutParams) customPanel.getLayoutParams()).weight = 0; } } else { customPanel.setVisibility(View.GONE); } }
From source file:group.pals.android.lib.ui.filechooser.FragmentFiles.java
/** * Setup://from www . j a va 2 s . c om * <p/> * <ul> * <li>button Cancel;</li> * <li>text field "save as" filename;</li> * <li>button OK;</li> * </ul> */ private void setupFooter() { /* * By default, view group footer and all its child views are hidden. */ ViewGroup viewGroupFooterContainer = (ViewGroup) getView() .findViewById(R.id.afc_viewgroup_footer_container); ViewGroup viewGroupFooter = (ViewGroup) getView().findViewById(R.id.afc_viewgroup_footer); if (mIsSaveDialog) { viewGroupFooterContainer.setVisibility(View.VISIBLE); viewGroupFooter.setVisibility(View.VISIBLE); mTextSaveas.setVisibility(View.VISIBLE); mTextSaveas.setText(getArguments().getString(FileChooserActivity.EXTRA_DEFAULT_FILENAME)); mTextSaveas.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { Ui.showSoftKeyboard(v, false); mBtnOk.performClick(); return true; } return false; }// onEditorAction() }); mTextSaveas.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { /* * Do nothing. */ }// onTextChanged() @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { /* * Do nothing. */ }// beforeTextChanged() @Override public void afterTextChanged(Editable s) { /* * If the user taps a file, the tag is set to that file's * URI. But if the user types the file name, we remove the * tag. */ mTextSaveas.setTag(null); }// afterTextChanged() }); mBtnOk.setVisibility(View.VISIBLE); mBtnOk.setOnClickListener(mBtnOk_SaveDialog_OnClickListener); mBtnOk.setBackgroundResource(Ui.resolveAttribute(getActivity(), R.attr.afc_selector_button_ok_saveas)); int size = getResources().getDimensionPixelSize(R.dimen.afc_button_ok_saveas_size); LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) mBtnOk.getLayoutParams(); lp.width = size; lp.height = size; mBtnOk.setLayoutParams(lp); } // this is in save mode else { if (mIsMultiSelection) { viewGroupFooterContainer.setVisibility(View.VISIBLE); viewGroupFooter.setVisibility(View.VISIBLE); ViewGroup.LayoutParams lp = viewGroupFooter.getLayoutParams(); lp.width = ViewGroup.LayoutParams.WRAP_CONTENT; viewGroupFooter.setLayoutParams(lp); mBtnOk.setMinWidth(getResources().getDimensionPixelSize(R.dimen.afc_single_button_min_width)); mBtnOk.setText(android.R.string.ok); mBtnOk.setVisibility(View.VISIBLE); mBtnOk.setOnClickListener(mBtnOk_OpenDialog_OnClickListener); } } // this is in open mode }