List of usage examples for android.view ViewGroup addView
public void addView(View child, int index, LayoutParams params)
From source file:Main.java
public static void startActivity(final Activity thisActivity, final Intent intent, final View triggerView, int colorOrImageRes, final long durationMills) { int[] location = new int[2]; triggerView.getLocationInWindow(location); final int cx = location[0] + triggerView.getWidth(); final int cy = location[1] + triggerView.getHeight() + (int) TypedValue .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 160, thisActivity.getResources().getDisplayMetrics()); final ImageView view = new ImageView(thisActivity); view.setScaleType(ImageView.ScaleType.CENTER_CROP); view.setImageResource(colorOrImageRes); final ViewGroup decorView = (ViewGroup) thisActivity.getWindow().getDecorView(); int w = decorView.getWidth(); int h = decorView.getHeight(); decorView.addView(view, w, h); final int finalRadius = (int) Math.sqrt(w * w + h * h) + 1; Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius); anim.setDuration(durationMills);/*www. java 2 s .com*/ anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); thisActivity.startActivity(intent); thisActivity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); } }); anim.start(); }
From source file:Main.java
private static void wrapView(View view, ViewGroup wrapper) { final ViewParent parent = view.getParent(); if (parent != null && parent instanceof ViewGroup) { final ViewGroup parentViewGroup = (ViewGroup) parent; // Wrapper should have same layout params as the previous view had ViewGroup.LayoutParams previousLayoutParams = view.getLayoutParams(); final int indexOfChild = parentViewGroup.indexOfChild(view); parentViewGroup.removeView(view); parentViewGroup.addView(wrapper, indexOfChild, previousLayoutParams); }/* w ww. ja va2 s. c o m*/ wrapper.addView(view); }
From source file:com.dv.View.PullToRefresh.ListFragment.DvBaseListFragment.java
@Override public final View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = super.onCreateView(inflater, container, savedInstanceState); ListView lv = (ListView) layout.findViewById(android.R.id.list); ViewGroup parent = (ViewGroup) lv.getParent(); // Remove ListView and add DvListView in its place int lvIndex = parent.indexOfChild(lv); parent.removeViewAt(lvIndex);// w w w .ja va 2 s .c o m mPullToRefreshListView = onCreatePullToRefreshListView(inflater, savedInstanceState); parent.addView(mPullToRefreshListView, lvIndex, lv.getLayoutParams()); return layout; }
From source file:com.benefit.buy.library.pulltorefresh.library.listfragment.PullToRefreshBaseListFragment.java
@Override public final View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = super.onCreateView(inflater, container, savedInstanceState); ListView lv = (ListView) layout.findViewById(android.R.id.list); ViewGroup parent = (ViewGroup) lv.getParent(); // Remove ListView and add PullToRefreshListView in its place int lvIndex = parent.indexOfChild(lv); parent.removeViewAt(lvIndex);/* ww w.j a v a2 s. co m*/ mPullToRefreshListView = onCreatePullToRefreshListView(inflater, savedInstanceState); parent.addView(mPullToRefreshListView, lvIndex, lv.getLayoutParams()); return layout; }
From source file:club.xlxk.libs.pulltorefresh.library.extras.PullToRefreshBaseListFragment.java
@Override public final View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = super.onCreateView(inflater, container, savedInstanceState); ListView lv = (ListView) layout.findViewById(android.R.id.list); ViewGroup parent = (ViewGroup) lv.getParent(); // Remove ListView and add PullToRefreshListView in its place int lvIndex = parent.indexOfChild(lv); parent.removeViewAt(lvIndex);//from w w w .j a v a2 s . c om mPullToRefreshListView = onCreatePullToRefreshListView(inflater, savedInstanceState); parent.addView(mPullToRefreshListView, lvIndex, lv.getLayoutParams()); return layout; }
From source file:com.umeng.comm.ui.imagepicker.adapters.ImagePagerAdapter.java
@Override public Object instantiateItem(ViewGroup container, int position) { if (mPresenter == null) { mPresenter = new ImageBrowserPresenter(container.getContext()); }// w w w .j av a2 s.c o m View view = createView(container, mPaths.get(position)); container.addView(view, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); return view; }
From source file:com.minglang.pulltorefreshlibrary.listfragment.PullToRefreshBaseListFragment.java
@Override public final View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layout = super.onCreateView(inflater, container, savedInstanceState); ListView lv = null;//ww w . j ava 2 s . c o m if (layout != null) { lv = (ListView) layout.findViewById(android.R.id.list); } ViewGroup parent = null; if (lv != null) { parent = (ViewGroup) lv.getParent(); } // Remove ListView and add PullToRefreshListView in its place int lvIndex = 0; if (parent != null) { lvIndex = parent.indexOfChild(lv); parent.removeViewAt(lvIndex); mPullToRefreshListView = onCreatePullToRefreshListView(inflater, savedInstanceState); parent.addView(mPullToRefreshListView, lvIndex, lv.getLayoutParams()); } return layout; }
From source file:com.ashlikun.badgeview.BadgeView.java
public void setTargetView(View target) { if (getParent() != null) { ((ViewGroup) getParent()).removeView(this); }//from w w w . j av a 2s . co m if (target == null) { return; } if (target.getParent() instanceof FrameLayout) { ((FrameLayout) target.getParent()).addView(this); } else if (target.getParent() instanceof ViewGroup) { // use a new Framelayout container for adding badge ViewGroup parentContainer = (ViewGroup) target.getParent(); int groupIndex = parentContainer.indexOfChild(target); parentContainer.removeView(target); FrameLayout badgeContainer = new FrameLayout(getContext()); ViewGroup.LayoutParams parentLayoutParams = target.getLayoutParams(); badgeContainer.setLayoutParams(parentLayoutParams); target.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); parentContainer.addView(badgeContainer, groupIndex, parentLayoutParams); badgeContainer.addView(target); badgeContainer.addView(this); } else if (target.getParent() == null) { Log.e(getClass().getSimpleName(), "ParentView is needed"); } }
From source file:com.rowland.hashtrace.ui.fragments.subfragment.TweetListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The ArrayAdapter will take data from a source and use it to populate the ListView it's attached to. mTweetListAdapter = new TweetListAdapter(getActivity(), null, 0); creator = new SwipeMenuCreator() { @Override// w w w .ja v a 2s . c o m public void create(SwipeMenu menu) { // create "share" item SwipeMenuItem shareItem = new SwipeMenuItem(getActivity().getApplicationContext()); // set item background shareItem.setBackground(new ColorDrawable(Color.rgb(211, 214, 219))); // set item width shareItem.setWidth(Utility.convertDpToPixel(100, getResources().getDisplayMetrics())); // set icon resource shareItem.setIcon(R.drawable.selector_swipemenuitem_share); // set item title shareItem.setTitle("Share"); // set item title fontsize shareItem.setTitleSize(18); // set item title font color shareItem.setTitleColor(Color.WHITE); // add to menu menu.addMenuItem(shareItem); // create "favour" item SwipeMenuItem favourItem = new SwipeMenuItem(getActivity().getApplicationContext()); // set item background favourItem.setBackground(new ColorDrawable(Color.rgb(211, 214, 219))); // set item width favourItem.setWidth(Utility.convertDpToPixel(100, getResources().getDisplayMetrics())); // set icon resource favourItem.setIcon(R.drawable.selector_swipemenuitem_favorite); // set item title favourItem.setTitle("Like"); // set item title fontsize favourItem.setTitleSize(18); // set item title font color favourItem.setTitleColor(Color.WHITE); // add to menu menu.addMenuItem(favourItem); } }; View rootView = inflater.inflate(R.layout.fragment_tweet_list, container, false); mListView = (SwipeMenuListView) rootView.findViewById(android.R.id.list); ViewGroup parent = (ViewGroup) mListView.getParent(); int lvIndex = parent.indexOfChild(mListView); if (mListView.getParent() != null) { parent.removeViewAt(lvIndex); } mListView.setVisibility(View.GONE); mPullToRefreshListView = new PullToRefreshSwipeMenuListView(getActivity()); mPullToRefreshListView.setLayoutParams(mListView.getLayoutParams()); parent.addView(mPullToRefreshListView, lvIndex, mListView.getLayoutParams()); View emptyView = rootView.findViewById(R.id.empty_text_view); mPullToRefreshListView.setEmptyView(emptyView); mPullToRefreshListView.setAdapter(mTweetListAdapter); mPullToRefreshListView.setMenuCreator(creator); mPullToRefreshListView.setVerticalFadingEdgeEnabled(true); mPullToRefreshListView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<SwipeMenuListView>() { @Override public void onRefresh(final PullToRefreshBase<SwipeMenuListView> refreshView) { // Do work to refresh the list here. updateTweet(); // Call onRefreshComplete when the list has been refreshed. refreshView.onRefreshComplete(); //mPullToRefreshListView.onRefreshComplete(); } }); //This somehow refuses to work , I really have no idea why /* mPullToRefreshListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long rowId) { Cursor cursor = mTweetListAdapter.getCursor(); if (cursor != null && cursor.moveToPosition(position)) { ((onTweetItemSelectedCallback) getActivity()).onTweetItemSelected(cursor.getString(COL_TWEET_TEXT_DATE)); Log.d("ROWSELECT", "" + rowId ); } mPosition = position; } });*/ mPullToRefreshListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long rowId) { // Do the onItemLongClick action mPullToRefreshListView.smoothOpenMenu(position); return true; } }); mPullToRefreshListView.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(int position, SwipeMenu menu, int index) { switch (index) { case 0: // Share shareTweet(); break; case 1: // Favourite favouriteTweet(); break; } // false : close the menu; true : not close the menu return false; } }); /** * Add Sound Event Listener */ SoundPullEventListener<SwipeMenuListView> soundListener = new SoundPullEventListener<SwipeMenuListView>( getActivity()); soundListener.addSoundEvent(State.PULL_TO_REFRESH, R.raw.pull_event_mp3); soundListener.addSoundEvent(State.RESET, R.raw.reset_sound_mp3); soundListener.addSoundEvent(State.REFRESHING, R.raw.refreshing_sound_mp3); mPullToRefreshListView.setOnPullEventListener(soundListener); mPullToRefreshListView.setCloseInterpolator(new BounceInterpolator()); // If there's instance state, mine it for useful information. The end-goal here is that // the user never knows that turning their device sideways does crazy lifecycle related things. if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) { // The listview probably hasn't even been populated yet. Actually // perform the swapout in onLoadFinished. mPosition = savedInstanceState.getInt(SELECTED_KEY); } return rootView; }
From source file:de.k3b.android.androFotoFinder.imagedetail.ImagePagerAdapterFromCursor.java
/** * Implementation for PagerAdapter:/*from w w w . j a va 2 s . com*/ * Create the page for the given position. The adapter is responsible * for adding the view to the container given here, although it only * must ensure this is done by the time it returns from * {@link #finishUpdate(ViewGroup)}. * * @param container The containing View in which the page will be shown. * @param position The page position to be instantiated. * @return Returns an Object representing the new page. This does not * need to be a View, but can be some other container of the page. */ @Override public View instantiateItem(ViewGroup container, int position) { Cursor cursor = getCursorAt(position); if (cursor != null) { long imageID = cursor.getLong(cursor.getColumnIndex(FotoSql.SQL_COL_PK)); Uri uri = getUri(imageID); PhotoView photoView = new PhotoView(container.getContext()); if (Global.debugEnabledViewItem) Log.i(Global.LOG_CONTEXT, debugPrefix + "instantiateItem(#" + position + ") => " + uri + " => " + photoView); setImage(position, imageID, uri, photoView); // Now just add PhotoView to ViewPager and return it container.addView(photoView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); return photoView; /* LinearLayout llImage = (LinearLayout) getLayoutInflater().inflate(R.layout.view_pager_item, null); SubsamplingScaleImageView draweeView = (SubsamplingScaleImageView) llImage.getChildAt(0); draweeView.setImage(ImageSource.uri(images.get(position))); container.addView(llImage, 0); return llImage; */ } return null; }