private ViewGroup setContentViewWithWrapper(int resContent) { ViewGroup decorView = (ViewGroup) this.getWindow().getDecorView(); ViewGroup decorChild = (ViewGroup) decorView.getChildAt(0); // Removing decorChild, we'll add it back soon decorView.removeAllViews(); ViewGroup wrapperView = new FrameLayout(this); // You should set some ID, if you'll want to reference this wrapper in that manner later // // The ID, such as "R.id.ACTIVITY_LAYOUT_WRAPPER" can be set at a resource file, such as: // <resources xmlns:android="http://schemas.android.com/apk/res/android"> // <item type="id" name="ACTIVITY_LAYOUT_WRAPPER"/> // </resources> // wrapperView.setId(R.id.ACTIVITY_LAYOUT_WRAPPER); // Now we are rebuilding the DecorView, but this time we // have our wrapper view to stand between the real content and the decor decorView.addView(wrapperView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); wrapperView.addView(decorChild, decorChild.getLayoutParams()); LayoutInflater.from(this).inflate(getActivityLayout(), (ViewGroup)((LinearLayout)wrapperView.getChildAt(0)).getChildAt(1), true); return wrapperView; }
arrowView.setId(ID_IMAGE_ARROW); progressView.setId(ID_IMAGE_PROGRESS); centerLayout.setId(android.R.id.widget_frame);
@Test public void dump_shouldDumpStructure() throws Exception { child3.setId(R.id.snippet_text); child3b.setVisibility(View.GONE); TextView textView = new TextView(context); textView.setText("Here's some text!"); textView.setVisibility(View.INVISIBLE); child3.addView(textView); ByteArrayOutputStream out = new ByteArrayOutputStream(); shadowOf(root).dump(new PrintStream(out), 0); assertEquals("<FrameLayout>\n" + " <View/>\n" + " <View/>\n" + " <FrameLayout id=\"org.robolectric:id/snippet_text\">\n" + " <View/>\n" + " <View visibility=\"GONE\"/>\n" + " <TextView visibility=\"INVISIBLE\" text=\"Here's some text!\"/>\n" + " </FrameLayout>\n" + "</FrameLayout>\n", out.toString()); }
drawer.mStickyFooterView.setId(R.id.material_drawer_sticky_footer); drawer.mSliderLayout.addView(drawer.mStickyFooterView, layoutParams);
@Override protected final void onInflateLayout(@NonNull final LayoutInflater inflater, final boolean tabsOnly) { if (tabsOnly) { toolbar = getTabSwitcher().findViewById(R.id.primary_toolbar); tabContainer = getTabSwitcher().findViewById(R.id.tab_container); } else { toolbar = (Toolbar) inflater.inflate(R.layout.phone_toolbar, getTabSwitcher(), false); getTabSwitcher().addView(toolbar); tabContainer = new FrameLayout(getContext()); tabContainer.setId(R.id.tab_container); getTabSwitcher().addView(tabContainer, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); } contentViewRecycler = new ViewRecycler<>(inflater); tabRecyclerAdapter = new PhoneTabRecyclerAdapter(getTabSwitcher(), getModel(), getStyle(), contentViewRecycler); getModel().addListener(tabRecyclerAdapter); tabViewRecycler = new AttachedViewRecycler<>(tabContainer, inflater, Collections.reverseOrder(new ItemComparator(getTabSwitcher()))); tabViewRecycler.setAdapter(tabRecyclerAdapter); tabRecyclerAdapter.setViewRecycler(tabViewRecycler); dragHandler = new PhoneDragTabsEventHandler(getTabSwitcher(), getArithmetics(), tabViewRecycler); adaptDecorator(); adaptToolbarMargin(); }
public Object instantiateItem(final ViewGroup container, final int position) { CustomHomeView RL = new CustomHomeView(MainActivity.ctxt); if (position==0){ container.setId(R.id.home_container);} ...rest of code
ViewGroup rightContainer = new FrameLayout(this); rightContainer.setId(View.generateViewId()); // you need an ID to perform a fragment transaction // api 17+ only, use static ID or copy/paste the code for lower platform LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 2); // the last param is the weight rightContainer.setLayoutParams(lp); linearLayout.addView(rightContainer); fragmentManager.beginTransaction() .add(rightContainer.getId(), ItemListFragment.newInstance(), "ITEM_LIST") // add custom transition if needed .commit();
private void init() { setOrientation(VERTICAL); mTitleViewGroup = new FrameLayout(getContext()); mTitleViewGroup.setId(DEFAULTTITLEPARENTRESID); addView(mTitleViewGroup); mContentViewGroup = new FrameLayout(getContext()); mContentViewGroup.setId(DEFAULTCONTENTPARENTRESID); addView(mContentViewGroup); } }
/** * Inflates the container, which contains the dialog's title, if it is not yet inflated. */ private void inflateTitleContainer() { if (titleContainer == null) { titleContainer = new RelativeLayout(getContext()); titleContainer.setId(R.id.title_container); titleContainer.setLayoutParams( new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } else { titleContainer.removeAllViews(); } }
/** * Inflates the container, which contains the dialog's message, if it is not yet inflated. */ private void inflateMessageContainer() { if (messageContainer == null) { messageContainer = new RelativeLayout(getContext()); messageContainer.setId(R.id.message_container); messageContainer.setLayoutParams( new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); } else { messageContainer.removeAllViews(); } }
/** * Inflates the container, which contains the dialog's content, if it is not yet inflated. */ private void inflateContentContainer() { if (contentContainer == null) { contentContainer = new RelativeLayout(getContext()); contentContainer.setId(R.id.content_container); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0); layoutParams.weight = 1; contentContainer.setLayoutParams(layoutParams); } else { contentContainer.removeAllViews(); } }
drawer.mStickyFooterView.setId(R.id.material_drawer_sticky_footer); drawer.mSliderLayout.addView(drawer.mStickyFooterView, layoutParams);
mContentRoot.setId(R.id.materialize_root);
@Test public void testWithParentInHierarchy() { // hierarchy A ViewGroup viewGroupParentA = new LinearLayout(context); viewGroupParentA.setId(TEST_PARENT_ID); addViewToLayout(viewGroupParentA, BaseActivity.rootLayout); ViewGroup viewGroupMidA = new LinearLayout(context); viewGroupMidA.setId(TEST_MID_ID); addViewToLayout(viewGroupMidA, TEST_PARENT_ID); // hierarchy B ViewGroup viewGroupParentB = new LinearLayout(context); viewGroupParentB.setId(TEST_PARENT_ID + 1); addViewToLayout(viewGroupParentB, BaseActivity.rootLayout); ViewGroup viewGroupMidB = new LinearLayout(context); viewGroupMidB.setId(TEST_MID_ID + 1); addViewToLayout(viewGroupMidB, TEST_PARENT_ID + 1); // view with same id on both hierarchies View viewSameIdA = new View(context); View viewSameIdB = new View(context); viewSameIdA.setId(TEST_ID); viewSameIdB.setId(TEST_ID); addViewToLayout(viewSameIdA, TEST_MID_ID); addViewToLayout(viewSameIdB, TEST_MID_ID + 1); builder.withId(TEST_ID).withParentInHierarchy(TEST_PARENT_ID).build().assertIsDisplayedOnScreen(); }