Android Imitation News reader Menu Pop-up effect example (source demo download) _android

Source: Internet
Author: User

After encountering problems in development, I think that maybe some developers use or want to be independent of a small function demo, so the release to such a demo.

Originally felt is the final completion of the site after the client, but this does not reflect a function of a function of the analysis to achieve results, and a long cycle time, so on the completion of a part, send a part, please understand.

The following menu pop-up effects are available on many news readers, such as today's headline, 360 News, and so on.

In fact, this realization is very simple, see the effect, is actually a popupwindow, then set the corresponding Postion button click Properties, and then get the button position, to set it animation display disappeared can appear.

Here's a look at the code's thinking:

Because the whole is a ListView, I write the clicked event to the corresponding adapter adapter.

public class Myadapter extends Baseadapter {layoutinflater inflater = null; 
  activity of activity; 
  Arraylist<news> newslist; 
 
  Private Popupwindow Popupwindow; 
    Public Myadapter (activity activity, arraylist<news> newslist) {this.activity = activity; 
    This.newslist = newslist; 
    Inflater = (layoutinflater) activity.getsystemservice (Context.layout_inflater_service); 
  Initpopwindow (); 
  @Override public int GetCount () {return newslist!= null? Newslist.size (): 0; 
      @Override public News getitem (int position) {if (newslist!= null && newslist.size ()!= 0) { 
    return Newslist.get (position); 
  return null; 
  @Override public long getitemid (int position) {return position; @Override Public View getview (final int position, View Convertview, ViewGroup parent) {View VI = CONVERTVI 
    ew 
    Final Viewholder Holder; if (vi = = NULL) {VI = Inflater.inflatE (R.layout.listview_item, NULL); 
      Holder = new Viewholder (); 
      Holder.item_title = (TextView) Vi.findviewbyid (r.id.item_title); 
      Holder.item_content = (TextView) Vi.findviewbyid (r.id.item_content); 
      Holder.button_showpop = (ImageView) Vi.findviewbyid (R.id.button_showpop); 
    Vi.settag (holder); 
    else {holder = (Viewholder) vi.gettag (); 
    News news = GetItem (position); 
    Holder.item_title.setText (News.gettitle ()); 
    Holder.item_content.setText (News.getcontent ()); 
    Holder.button_showpop. Setonclicklistener (new popaction (position)); 
  return VI; 
    public class Viewholder {TextView item_title; 
    TextView item_content; 
  ImageView Button_showpop; /** * Initialize Popwindow */private void Initpopwindow () {View Popview = inflater.inflate (r.layout.l 
    Istview_pop, NULL); 
    Popupwindow = new Popupwindow (Popview, layoutparams.wrap_content, layoutparams.wrap_content); Popupwindow.setbacKgrounddrawable (new colordrawable (0)); 
    Set Popwindow to appear and disappear animation Popupwindow.setanimationstyle (r.style.popmenuanimation); 
  Btn_pop_close = (ImageView) Popview.findviewbyid (r.id.btn_pop_close); 
   
  /** Popwindow Close button * * Private ImageView btn_pop_close; 
    /** * Show Popwindow */public void Showpop (View parent, int x, int y,int postion) {//Set Popwindow display location 
    Popupwindow.showatlocation (parent, 0, X, y); 
    Gets Popwindow Focus popupwindow.setfocusable (TRUE); 
    Set Popwindow If you click on the outside area, then close. 
    Popupwindow.setoutsidetouchable (TRUE); 
    Popupwindow.update (); if (popupwindow.isshowing ()) {} btn_pop_close.setonclicklistener (new Onclicklistener () {public 
      void OnClick (View paramview) {Popupwindow.dismiss (); 
  } 
    }); 
    /** * per item more button corresponding Click action * */public class Popaction implements onclicklistener{int position; public popaction (int position) {this.position = Position 
      @Override public void OnClick (View v) {int[] Arrayofint = new int[2]; 
      Get the coordinates of the click button V.getlocationonscreen (arrayofint); 
      int x = arrayofint[0]; 
      int y = arrayofint[1]; 
    Showpop (v, x, y, position); 
 } 
  } 
}

So much content, very simple, in the future encounter this kind of related effect, also don't be afraid.

Here's what I've accomplished with the above code:

Below put on the effect source demo download Address: Download the address

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.