List of usage examples for android.view ViewGroup addView
public void addView(View child)
Adds a child view.
From source file:com.umeng.comm.ui.emoji.EmojiBorad.java
/** * init. Set params and add show emoji views</br> *///w ww. j a v a 2 s .c o m private void init() { computeBoardHeight(); setOrientation(LinearLayout.VERTICAL); setBackgroundColor(Color.parseColor("#f4f4f6")); ViewPager viewPager = createVIewpager(); addView(viewPager); ViewGroup container = createPointLinearlayout(); List<EmojiView> datas = new ArrayList<EmojiView>(); int lens = People.DATA.length; int pages = lens / PAGE_SIZE; // pages? for (int i = 0; i < pages; i++) { EmojiBean[] blocks = new EmojiBean[PAGE_SIZE + 1]; System.arraycopy(People.DATA, i * PAGE_SIZE, blocks, 0, blocks.length - 1); blocks[PAGE_SIZE] = EmojiBean.fromChars(DELETE_KEY); datas.add(new EmojiView(getContext(), blocks)); // the last is // delete icon } // add remain emoji view if (pages * PAGE_SIZE < lens) { EmojiBean[] blocks = new EmojiBean[lens - pages * PAGE_SIZE]; System.arraycopy(People.DATA, pages * PAGE_SIZE, blocks, 0, blocks.length); datas.add(new EmojiView(getContext(), blocks)); } // add indicator for (int i = 0; i < datas.size(); i++) { ImageView indicatorView = createIndicator(); mIndicators.add(indicatorView); container.addView(indicatorView); } addView(container); size = datas.size(); // set cache view count viewPager.setOffscreenPageLimit(datas.size()); // mIndicators.get(mLastSelectViewPos).setImageDrawable(ResFinder.getDrawable(mSelectIcon)); mAdapter = new EmojiPagerAdapter(getContext(), datas); viewPager.setAdapter(mAdapter); viewPager.setOnPageChangeListener(this); }
From source file:at.alladin.rmbt.android.views.ResultQoSDetailView.java
@SuppressWarnings("unchecked") @Override/*from w w w . j a v a 2 s . c o m*/ public void taskEnded(JSONArray result) { System.out.println("ResultQoSDetail taskEnded"); this.testResult = result; if (resultFetchEndTaskListener != null) { resultFetchEndTaskListener.taskEnded(result); } ProgressBar resultProgressBar = (ProgressBar) view.findViewById(R.id.progress_bar); TextView resultTextView = (TextView) view.findViewById(R.id.info_text); try { results = new QoSServerResultCollection(result); View successList = view.findViewById(R.id.qos_success_list); List<HashMap<String, String>> itemList = new ArrayList<HashMap<String, String>>(); int index = 0; for (QoSTestResultEnum type : QoSTestResultEnum.values()) { if (results.getQoSStatistics().getTestCounter(type) > 0) { HashMap<String, String> listItem = new HashMap<String, String>(); listItem.put("name", ConfigHelper.getCachedQoSNameByTestType(type, activity)); listItem.put("type_name", type.toString()); listItem.put("index", String.valueOf(index++)); itemList.add(listItem); } } ListAdapter valueList = new SimpleAdapter(activity, itemList, R.layout.qos_category_list_item, new String[] { "name" }, new int[] { R.id.name }); resultProgressBar.setVisibility(View.GONE); if (valueList.getCount() > 0) { //in case the view will change again: if (ListView.class.isAssignableFrom(successList.getClass())) { ((ListView) successList).setAdapter(valueList); ((ListView) successList).setOnItemClickListener(this); } else { ViewGroup vgList = (ViewGroup) successList; for (int i = 0; i < valueList.getCount(); i++) { View v = valueList.getView(i, null, null); QoSTestResultEnum key = QoSTestResultEnum .valueOf(((HashMap<String, String>) valueList.getItem(i)).get("type_name")); if (results.getQoSStatistics().getFailureCounter(key) > 0) { ImageView img = (ImageView) v.findViewById(R.id.status); img.setImageResource(R.drawable.traffic_lights_red); } TextView status = (TextView) v.findViewById(R.id.qos_type_status); status.setText((results.getQoSStatistics().getTestCounter(key) - results.getQoSStatistics().getFailedTestsCounter(key)) + "/" + results.getQoSStatistics().getTestCounter(key)); v.setOnClickListener(this); v.setTag(valueList.getItem(i)); vgList.addView(v); } } successList.invalidate(); resultTextView.setVisibility(View.GONE); successList.setVisibility(View.VISIBLE); } else { resultTextView.setText(R.string.result_qos_error_no_data_available); } } catch (Throwable t) { resultTextView.setText(R.string.result_qos_error_no_data_available); resultProgressBar.setVisibility(View.GONE); t.printStackTrace(); } }
From source file:com.umeng.comm.ui.imagepicker.emoji.EmojiBorad.java
/** * init. Set params and setList show emoji views</br> *//*from w w w .j av a 2s. c om*/ private void init() { computeBoardHeight(); setOrientation(LinearLayout.VERTICAL); setBackgroundColor(Color.parseColor("#f4f4f6")); ViewPager viewPager = createVIewpager(); addView(viewPager); ViewGroup container = createPointLinearlayout(); List<EmojiView> datas = new ArrayList<EmojiView>(); int lens = People.DATA.length; int pages = lens / PAGE_SIZE; // pages? for (int i = 0; i < pages; i++) { EmojiBean[] blocks = new EmojiBean[PAGE_SIZE + 1]; System.arraycopy(People.DATA, i * PAGE_SIZE, blocks, 0, blocks.length - 1); blocks[PAGE_SIZE] = EmojiBean.fromChars(DELETE_KEY); datas.add(new EmojiView(getContext(), blocks)); // the last is // icon_delete icon } // setList remain emoji view if (pages * PAGE_SIZE < lens) { EmojiBean[] blocks = new EmojiBean[lens - pages * PAGE_SIZE]; System.arraycopy(People.DATA, pages * PAGE_SIZE, blocks, 0, blocks.length); datas.add(new EmojiView(getContext(), blocks)); } // setList indicator for (int i = 0; i < datas.size(); i++) { ImageView indicatorView = createIndicator(); mIndicators.add(indicatorView); container.addView(indicatorView); } addView(container); size = datas.size(); // set cache view count viewPager.setOffscreenPageLimit(datas.size()); // mIndicators.get(mLastSelectViewPos).setImageDrawable(ResFinder.getDrawable(mSelectIcon)); mAdapter = new EmojiPagerAdapter(getContext(), datas); viewPager.setAdapter(mAdapter); viewPager.setOnPageChangeListener(this); }
From source file:com.github.cpmproto.categorystepfragment.base.GuidedStepListFragment.java
/** * {@inheritDoc}//from w w w . j av a 2 s . co m */ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (DEBUG) Log.v(TAG, "onCreateView"); resolveTheme(); inflater = getThemeInflater(inflater); rootLayout = (GuidedStepRootLayout) inflater.inflate(R.layout.lb_guidedstep_fragment, container, false); rootLayout.setFocusOutStart(isFocusOutStartAllowed()); rootLayout.setFocusOutEnd(isFocusOutEndAllowed()); rootLayout.setBackgroundColor(Color.TRANSPARENT); rootLayout.setOnKeyPress(this); ViewGroup guidanceContainer = (ViewGroup) rootLayout.findViewById(R.id.content_fragment); guidanceContainer.setVisibility(View.INVISIBLE); ViewGroup actionContainer = (ViewGroup) rootLayout.findViewById(R.id.action_fragment); View actionsView = mActionsStylist.onCreateView(inflater, actionContainer); actionContainer.addView(actionsView); View buttonActionsView = mButtonActionsStylist.onCreateView(inflater, actionContainer); actionContainer.addView(buttonActionsView); GuidedActionAdapter.EditListener editListener = new GuidedActionAdapter.EditListener() { @Override public void onImeOpen() { runImeAnimations(true); } @Override public void onImeClose() { runImeAnimations(false); } @Override public long onGuidedActionEditedAndProceed(GuidedAction action) { return GuidedStepListFragment.this.onGuidedActionEditedAndProceed(action); } @Override public void onGuidedActionEditCanceled(GuidedAction action) { GuidedStepListFragment.this.onGuidedActionEditCanceled(action); } }; mAdapter = new GuidedActionAdapter(getActionsByKey(), new GuidedActionAdapter.ClickListener() { @Override public void onGuidedActionClicked(GuidedAction action) { GuidedStepListFragment.this.onGuidedActionClicked(action); if (isSubActionsExpanded()) { collapseSubActions(); } else if (action.hasSubActions()) { expandSubActions(action); } } }, this, mActionsStylist, false); mButtonAdapter = new GuidedActionAdapter(mButtonActions, new GuidedActionAdapter.ClickListener() { @Override public void onGuidedActionClicked(GuidedAction action) { GuidedStepListFragment.this.onGuidedActionClicked(action); } }, this, mButtonActionsStylist, false); mSubAdapter = new GuidedActionAdapter(null, new GuidedActionAdapter.ClickListener() { @Override public void onGuidedActionClicked(GuidedAction action) { if (mActionsStylist.isInExpandTransition()) { return; } if (GuidedStepListFragment.this.onSubGuidedActionClicked(action)) { collapseSubActions(); } rootLayout.setOnSubcategoryfocus(false); setActions(mActions, action.toString()); } }, this, mActionsStylist, true); mAdapterGroup = new GuidedActionAdapterGroup(); mAdapterGroup.addAdpter(mAdapter, mButtonAdapter); mAdapterGroup.addAdpter(mSubAdapter, null); mAdapterGroup.setEditListener(editListener); mActionsStylist.setEditListener(editListener); mActionsStylist.getActionsGridView().setAdapter(mAdapter); if (mActionsStylist.getSubActionsGridView() != null) { mActionsStylist.getSubActionsGridView().setAdapter(mSubAdapter); } mButtonActionsStylist.getActionsGridView().setAdapter(mButtonAdapter); if (mButtonActions.size() == 0) { // when there is no button actions, we don't need show the second panel, but keep // the width zero to run ChangeBounds transition. LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) buttonActionsView.getLayoutParams(); lp.weight = 0; buttonActionsView.setLayoutParams(lp); } else { // when there are two actions panel, we need adjust the weight of action to // guidedActionContentWidthWeightTwoPanels. Context ctx = mThemeWrapper != null ? mThemeWrapper : getActivity(); TypedValue typedValue = new TypedValue(); if (ctx.getTheme().resolveAttribute(R.attr.guidedActionContentWidthWeightTwoPanels, typedValue, true)) { View actionsRoot = rootLayout.findViewById(R.id.action_fragment_root); float weight = typedValue.getFloat(); LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) actionsRoot.getLayoutParams(); lp.weight = weight; actionsRoot.setLayoutParams(lp); } } int pos = (mSelectedIndex >= 0 && mSelectedIndex < mActions.size()) ? mSelectedIndex : getFirstCheckedAction(); setSelectedActionPosition(pos); setSelectedButtonActionPosition(0); return rootLayout; }
From source file:com.activiti.android.ui.form.FormManager.java
private BaseField generateField(FormFieldRepresentation data, ViewGroup hookView, boolean isEdition) { boolean tmpIsEdition = isEdition; // First we prepare the field String dataType = (tmpIsEdition) ? data.getType() : data.getReadOnlyFieldType(); // ReadOnly is a specific case // We don't use type but the type defined by params. // Works like a pointer to a specific field if (FormFieldTypes.READONLY.equals(dataType)) { dataType = data.getReadOnlyFieldType(); tmpIsEdition = false;//www .j a v a 2 s .co m } BaseField field = FieldTypeFactory.createField(getActivity(), this, dataType, data, !tmpIsEdition); // Then we create the view View fieldView = (tmpIsEdition) ? field.setupEditionView(data.getValue()) : field.setupdReadView(); // If a view has been generated we kept it. if (fieldView != null) { hookView.addView(fieldView); } return field; }
From source file:com.heneryh.aquanotes.ui.controllers.ControllersActivity.java
/** * Build and add "notes" tab.//from w w w . j a v a 2 s. co m */ private void setupNotesTab(Ctlr ctlr) { /** * nearly all of the comments here are the same as for the probes. */ String tagSpec = TAG_NOTES + "_" + ctlr.mControllerId.toString().replace('-', 'n'); int Rid; switch (ctlr.index) { case 0: Rid = R.id.fragment_notes_0; break; case 1: Rid = R.id.fragment_notes_1; break; case 2: Rid = R.id.fragment_notes_2; break; case 3: Rid = R.id.fragment_notes_3; break; case 4: Rid = R.id.fragment_notes_4; break; case 5: Rid = R.id.fragment_notes_5; break; case 6: Rid = R.id.fragment_notes_6; break; case 7: Rid = R.id.fragment_notes_7; break; case 8: Rid = R.id.fragment_notes_8; break; case 9: Rid = R.id.fragment_notes_9; break; default: Rid = 0; } /** * Build the intent that will be sent to the fragment */ final Intent intent = new Intent(Intent.ACTION_VIEW, Controllers.buildQueryControllerXUri(ctlr.mControllerId)); intent.putExtra("ControllerName", ctlr.mTitleString); ctlr.notesFragmentContainer = new FrameLayout(this); ctlr.notesFragmentContainer.setId(Rid); ViewGroup tabContentView = (ViewGroup) ctlr.mRootView.findViewById(android.R.id.tabcontent); tabContentView.addView(ctlr.notesFragmentContainer); final FragmentManager fm = getSupportFragmentManager(); ctlr.mNotesFragment = (NotesFragment) fm.findFragmentByTag(tagSpec); if (ctlr.mNotesFragment == null) { ctlr.mNotesFragment = new NotesFragment(); ctlr.mNotesFragment.setArguments(intentToFragmentArguments(intent)); fm.beginTransaction().add(Rid, ctlr.mNotesFragment, tagSpec).commit(); } ctlr.mTabHost.addTab(ctlr.mTabHost.newTabSpec(tagSpec) .setIndicator(buildIndicator(ctlr, R.string.notes_tab_title)).setContent(Rid)); }
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 . ja v a2s . c o m*/ 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:com.heneryh.aquanotes.ui.controllers.ControllersActivity.java
/** * Build and add "sessions" tab./*from w w w .j ava2 s .c o m*/ */ private void setupOutletsTab(Ctlr ctlr) { /** * nearly all of the comments here are the same as for the probes. */ String tagSpec = TAG_OUTLETS + "_" + ctlr.mControllerId.toString().replace('-', 'n'); int Rid; switch (ctlr.index) { case 0: Rid = R.id.fragment_outlets_0; break; case 1: Rid = R.id.fragment_outlets_1; break; case 2: Rid = R.id.fragment_outlets_2; break; case 3: Rid = R.id.fragment_outlets_3; break; case 4: Rid = R.id.fragment_outlets_4; break; case 5: Rid = R.id.fragment_outlets_5; break; case 6: Rid = R.id.fragment_outlets_6; break; case 7: Rid = R.id.fragment_outlets_7; break; case 8: Rid = R.id.fragment_outlets_8; break; case 9: Rid = R.id.fragment_outlets_9; break; default: Rid = 0; } ctlr.outletsFragmentContainer = new FrameLayout(this); ctlr.outletsFragmentContainer.setId(Rid); ctlr.outletsFragmentContainer.setLayoutParams( new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); ViewGroup tabContentView = (ViewGroup) ctlr.mRootView.findViewById(android.R.id.tabcontent); tabContentView.addView(ctlr.outletsFragmentContainer); final Intent intent = new Intent(Intent.ACTION_VIEW, Data.buildQueryODataAtUri(ctlr.mControllerId, ctlr.mTimestamp)); final FragmentManager fm = getSupportFragmentManager(); ctlr.mOutletsFragment = (OutletsDataFragment) fm.findFragmentByTag(tagSpec); // was OutletXFragment if (ctlr.mOutletsFragment == null) { ctlr.mOutletsFragment = new OutletsDataFragment(); // was OutletXFragment ctlr.mOutletsFragment.setArguments(intentToFragmentArguments(intent)); fm.beginTransaction().add(Rid, ctlr.mOutletsFragment, tagSpec).commit(); } ctlr.mTabHost.addTab(ctlr.mTabHost.newTabSpec(tagSpec) .setIndicator(buildIndicator(ctlr, R.string.outlets_tab_title)).setContent(Rid)); // ctlr.mTabManager.addTab(ctlr.mTabHost.newTabSpec(tagSpec) // .setIndicator("Outlets")//buildIndicator(ctlr, R.string.outlets_tab_title)) // .setContent(Rid), // OutletsDataFragment.class, // Rid, // intentToFragmentArguments(intent)); }
From source file:com.heneryh.aquanotes.ui.controllers.ControllersActivity.java
/** * Build and add "graphs" tab./* w ww .ja v a2s . c o m*/ */ private void setupGraphsTab(Ctlr ctlr, String probeName) { /** * nearly all of the comments here are the same as for the probes. */ String tagSpec = TAG_GRAPHS + "_" + ctlr.mControllerId.toString().replace('-', 'n'); int Rid; switch (ctlr.index) { case 0: Rid = R.id.fragment_graphs_0; break; case 1: Rid = R.id.fragment_graphs_1; break; case 2: Rid = R.id.fragment_graphs_2; break; case 3: Rid = R.id.fragment_graphs_3; break; case 4: Rid = R.id.fragment_graphs_4; break; case 5: Rid = R.id.fragment_graphs_5; break; case 6: Rid = R.id.fragment_graphs_6; break; case 7: Rid = R.id.fragment_graphs_7; break; case 8: Rid = R.id.fragment_graphs_8; break; case 9: Rid = R.id.fragment_graphs_9; break; default: Rid = 0; } /** * Don't think these are used anymore */ ctlr.graphsTagId = tagSpec; ctlr.graphsRid = Rid; /** * Build the intent that will be sent to the fragment */ final Intent intent = new Intent(Intent.ACTION_VIEW, Controllers.buildQueryControllerXUri(ctlr.mControllerId)); if (probeName == null) intent.putExtra("ProbeName", "none"); else intent.putExtra("ProbeName", probeName); // this was an attempt at updating the fragment... ctlr.graphsFragmentContainer = new FrameLayout(this); ctlr.graphsFragmentContainer.setId(Rid); ViewGroup tabContentView = (ViewGroup) ctlr.mRootView.findViewById(android.R.id.tabcontent); tabContentView.addView(ctlr.graphsFragmentContainer); final FragmentManager fm = getSupportFragmentManager(); ctlr.mGraphsFragment = (GraphsFragment) fm.findFragmentByTag(tagSpec); if (ctlr.mGraphsFragment == null) { ctlr.mGraphsFragment = new GraphsFragment(); ctlr.mGraphsFragment.setArguments(intentToFragmentArguments(intent)); fm.beginTransaction().add(Rid, ctlr.mGraphsFragment, tagSpec).commit(); } ctlr.mTabHost.addTab(ctlr.mTabHost.newTabSpec(tagSpec) .setIndicator(buildIndicator(ctlr, R.string.graphs_tab_title)).setContent(Rid)); // ctlr.mTabManager.addTab(ctlr.mTabHost.newTabSpec(tagSpec) // .setIndicator("Graphs")//buildIndicator(ctlr, R.string.graphs_tab_title)) // .setContent(Rid), // GraphsFragment.class, // Rid, // intentToFragmentArguments(intent)); }
From source file:com.hybris.mobile.lib.ui.view.Alert.java
/** * Set the icon on the alert// ww w . j av a2s . c o m * * @param context application-specific resources * @param configuration describes all device configuration information * @param mainView ViewGroup resources * @param textView alert message to be viewed message to be displayedView */ @SuppressLint("NewApi") private static void setIcon(Activity context, Configuration configuration, ViewGroup mainView, TextView textView) { ImageView imageView = (ImageView) mainView.findViewById(R.id.alert_view_icon); // Reset the current icon if (imageView != null) { mainView.removeView(imageView); } // On the textview as well textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); textView.setCompoundDrawablePadding(0); if (configuration.getIconResId() != -1) { imageView = new ImageView(context); imageView.setId(R.id.alert_view_icon); imageView.setImageResource(configuration.getIconResId()); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); imageView.setLayoutParams(layoutParams); switch (configuration.getIconPosition()) { case LEFT_TEXT: textView.setCompoundDrawablesWithIntrinsicBounds(configuration.getIconResId(), 0, 0, 0); textView.setCompoundDrawablePadding(10); break; case RIGHT_TEXT: textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, configuration.getIconResId(), 0); textView.setCompoundDrawablePadding(10); break; case LEFT: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START); } layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); layoutParams.setMargins(25, 0, 0, 0); mainView.addView(imageView); // We redefine the layout params otherwise the image is not well aligned textView.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); break; case RIGHT: default: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { layoutParams.addRule(RelativeLayout.ALIGN_PARENT_END); } layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); layoutParams.setMargins(0, 0, 25, 0); mainView.addView(imageView); // We redefine the layout params otherwise the image is not well aligned textView.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); break; } } }