十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
这篇文章主要介绍了Android如何实现底部缓慢弹出菜单,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
创新互联长期为成百上千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为拉孜企业提供专业的成都网站建设、成都网站制作,拉孜网站改版等技术服务。拥有十多年丰富建站经验和众多成功案例,为您定制开发。
项目要求要做一个从底部缓慢弹出一个Button Menu
开始编码:
MyselfFragment
package io.dcloud.H5B79C397.fragment; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.RelativeLayout; import android.widget.Toast; import com.android.volley.VolleyError; import com.vanda.vandalibnetwork.fragment.BaseFragment; import java.util.Map; import cn.sharesdk.framework.ShareSDK; import cn.sharesdk.onekeyshare.OnekeyShare; import cn.sharesdk.sina.weibo.SinaWeibo; import cn.sharesdk.tencent.qq.QQ; import cn.sharesdk.wechat.friends.Wechat; import cn.sharesdk.wechat.moments.WechatMoments; import io.dcloud.H5B79C397.R; import io.dcloud.H5B79C397.Urls; import io.dcloud.H5B79C397.activity.BottomMenu; import io.dcloud.H5B79C397.activity.LoginActivity; import io.dcloud.H5B79C397.activity.Myself_About_fae; import io.dcloud.H5B79C397.activity.Myself_Invitation; import io.dcloud.H5B79C397.activity.Myself_help; import io.dcloud.H5B79C397.activity.Myself_setting; import io.dcloud.H5B79C397.activity.RegisterActivity; import io.dcloud.H5B79C397.activity.user_management; import io.dcloud.H5B79C397.pojo.InformmationData; import io.dcloud.H5B79C397.util.ActionBarUtil; import io.dcloud.H5B79C397.util.ExtUtils; /** * 用户个人信息界面 */ public class MyselfFragment extends BaseFragmentimplements View.OnClickListener { private Context mContext; private View view; private BottomMenu menuWindow; private RelativeLayout layout_advise, layout_collect, layout_logo, layout_share, layout_qr_code, layout_help, layout_set, layout_url; private Button btnLogin, btnRegister; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.inflate(R.layout.fragment_information, container, false); initView(); return view; } @Override public void onStart() { super.onStart(); } private void initView() { new ActionBarUtil(view, R.id.actionBar, R.id.Back, R.id.Title, R.id.Activity, "我的管理中心", getActivity(), 2); layout_advise = (RelativeLayout) view.findViewById(R.id.myself_advise); layout_collect = (RelativeLayout) view.findViewById(R.id.myself_collect); layout_logo = (RelativeLayout) view.findViewById(R.id.myself_logo); layout_share = (RelativeLayout) view.findViewById(R.id.myself_share); layout_qr_code = (RelativeLayout) view.findViewById(R.id.myself_qr_code); layout_help = (RelativeLayout) view.findViewById(R.id.myself_help); layout_set = (RelativeLayout) view.findViewById(R.id.myself_set); layout_url = (RelativeLayout) view.findViewById(R.id.myself_url); btnLogin = (Button) view.findViewById(R.id.myself_login); btnRegister = (Button) view.findViewById(R.id.myself_register); layout_advise.setOnClickListener(this); layout_collect.setOnClickListener(this); layout_logo.setOnClickListener(this); layout_share.setOnClickListener(this); layout_qr_code.setOnClickListener(this); layout_help.setOnClickListener(this); layout_set.setOnClickListener(this); layout_url.setOnClickListener(this); btnLogin.setOnClickListener(this); btnRegister.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.myself_advise: startActivity(new Intent(getActivity(), user_management.class)); break; case R.id.myself_collect: break; case R.id.myself_logo: Intent intent=new Intent(getActivity(),Myself_About_fae.class); startActivity(intent); break; case R.id.myself_share: menuWindow = new BottomMenu(mContext, clickListener); menuWindow.show(); break; case R.id.myself_qr_code: startActivity(new Intent(getActivity(), Myself_Invitation.class)); break; case R.id.myself_help: startActivity(new Intent(getActivity(), Myself_help.class)); break; case R.id.myself_set: startActivity(new Intent(getActivity(), Myself_setting.class)); break; case R.id.myself_url: Uri uri = Uri.parse("http://www.fae.cn/"); Intent intent1 = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent1); break; case R.id.myself_login: startActivity(new Intent(getActivity(), LoginActivity.class)); break; case R.id.myself_register: startActivity(new Intent(getActivity(), RegisterActivity.class)); break; default: break; } } private View.OnClickListener clickListener = new View.OnClickListener(){ public void onClick(View v) { switch (v.getId()) { case R.id.btn1: showZiDingYi(Wechat.NAME); break; case R.id.btn2: showZiDingYi(WechatMoments.NAME); Toast.makeText(mContext,"这是微信朋友圈",Toast.LENGTH_SHORT).show(); break; case R.id.sina: showZiDingYi(SinaWeibo.NAME); break; case R.id.QQ: showZiDingYi(QQ.NAME); break; case R.id.more: Toast.makeText(mContext,"这是更多",Toast.LENGTH_SHORT).show(); break; default: break; } } }; private void showZiDingYi(String ss){ ShareSDK.initSDK(getActivity()); OnekeyShare oks = new OnekeyShare(); oks.setSilent(false); oks.setDialogMode(); oks.setText("xxxxxxxxx"); //oks.setImageUrl("http://sharesdk.cn"); oks.setPlatform(ss); oks.show(getActivity()); } public static MyselfFragment newInstance(Context context) { MyselfFragment fragment = new MyselfFragment(); fragment.mContext = context; return fragment; } public MyselfFragment() { // Required empty public constructor } @Override protected void processData(InformmationData response) { super.processData(response); if (response != null) { } } @Override protected void errorData(VolleyError volleyError) { super.errorData(volleyError); ExtUtils.errorLog("-----MyselfFragment----volleyError--------->", volleyError + ""); } @Override protected String getRequestUrl() { return Urls.URL_PREFIX + ""; } @Override protected Class getResponseDataClass() { return InformmationData.class; } @Override protected Map getParamMap() { return null; } }
BottomMenu
package io.dcloud.H5B79C397.activity; import android.app.ActionBar; import android.app.Activity; import android.content.Context; import android.graphics.drawable.ColorDrawable; import android.view.Gravity; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.PopupWindow; import io.dcloud.H5B79C397.R; import static io.dcloud.H5B79C397.R.id.btn1; import static io.dcloud.H5B79C397.R.id.btn2; /** * Created by Administrator on 2017/7/21 0021. */ public class BottomMenu implements View.OnClickListener,View.OnTouchListener { private PopupWindow popupWindow; private Button wechat, friend,qq,sina,more ,btnCancel; private View mMenuView; private Activity mContext; private View.OnClickListener clickListener; public BottomMenu(Context context, View.OnClickListener clickListener) { LayoutInflater inflater = LayoutInflater.from(context); this.clickListener=clickListener; mContext= (Activity) context; mMenuView = inflater.inflate(R.layout.layout_popwindow, null); wechat= (Button) mMenuView.findViewById(btn1); friend= (Button) mMenuView.findViewById(btn2); qq=(Button)mMenuView.findViewById(R.id.QQ) ; sina=(Button)mMenuView.findViewById(R.id.sina); more=(Button)mMenuView.findViewById(R.id.more); btnCancel = (Button) mMenuView.findViewById(R.id.btn_cancel); btnCancel.setOnClickListener(this); wechat.setOnClickListener(this); friend.setOnClickListener(this); qq.setOnClickListener(this); sina.setOnClickListener(this); more.setOnClickListener(this); popupWindow=new PopupWindow(mMenuView, ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.WRAP_CONTENT,true); popupWindow.setAnimationStyle(R.style.popwin_anim_style); ColorDrawable dw = new ColorDrawable(context.getResources().getColor(R.color.apha)); popupWindow.setBackgroundDrawable(dw); mMenuView.setOnTouchListener(this); } /** * 显示菜单 */ public void show(){ //得到当前activity的rootView View rootView=((ViewGroup)mContext.findViewById(android.R.id.content)).getChildAt(0); popupWindow.showAtLocation(rootView, Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0); } @Override public void onClick(View view) { popupWindow.dismiss(); switch (view.getId()) { case R.id.btn_cancel: break; default: clickListener.onClick(view); break; } } @Override public boolean onTouch(View arg0, MotionEvent event) { int height = mMenuView.findViewById(R.id.pop_layout).getTop(); int y=(int) event.getY(); if(event.getAction()==MotionEvent.ACTION_UP){ if(ylayout_popwindow.xml
包anim//放在res目录下其中包括ppwindow_hide_anim.xml和ppwindow_show_anim.xml
其中ppwindow_hide_anim.xml其中ppwindow_show_anim.xml
最后上图:
感谢你能够认真阅读完这篇文章,希望小编分享的“Android如何实现底部缓慢弹出菜单”这篇文章对大家有帮助,同时也希望大家多多支持创新互联,关注创新互联行业资讯频道,更多相关知识等着你来学习!
分享文章:Android如何实现底部缓慢弹出菜单
网站路径:http://shouzuofang.com/article/jigjjd.html