Android PopupWindow实现,类似于iOS的选择栏

转载请注明出处:王亟亟的大牛之路

以前项目中也做过类似的东西,今天想到就写一篇关于这样的东西了,外面这一类的实现也很多,都可以借鉴,但是,谢了也就写了,,嗯!! 项目结构:

运行效果

完成了布局的圆角,弹出弹出的动画以及一系列监听事件

主Activity

{Button showPopupWindow;TextView mServerLogin;TextView mSmsLogin;TextView mSmsCancel;View root;private PopupWindow popupWindow;(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);showPopupWindow=(Button)findViewById(R.id.showPopupWindow);showPopupWindow.setOnClickListener(this);// 父窗口viewroot = findViewById(R.id.root);//初始化initPopupWindow();}(Menu menu) {getMenuInflater().inflate(R.menu.main, menu);return true;}(MenuItem item) {id = item.getItemId();if (id == R.id.action_settings) {return true;}return super.onOptionsItemSelected(item);}(View v) {switch (v.getId()) {case R.id.showPopupWindow:popupWindow.showAtLocation(root, Gravity.BOTTOM, 0, 0);break;case R.id.mServerLogin:Toast.makeText(MainActivity.this, “登录”, Toast.LENGTH_SHORT).show();break;case R.id.mSmsLogin:Toast.makeText(MainActivity.this, “注册”, Toast.LENGTH_SHORT).show();break;case R.id.mSmsCancel:if (popupWindow.isShowing())popupWindow.dismiss();break;default:break;}}(){View view=getLayoutInflater().inflate(R.layout.dialog, null);mServerLogin = (TextView) view.findViewById(R.id.mServerLogin);mSmsLogin = (TextView) view.findViewById(R.id.mSmsLogin);mSmsCancel= (TextView) view.findViewById(R.id.mSmsCancel);mServerLogin.setOnClickListener(this);mSmsLogin.setOnClickListener(this);mSmsCancel.setOnClickListener(this);// 全屏显示,将内容设置在底部popupWindow = new PopupWindow(view,ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);popupWindow.setOutsideTouchable(false);popupWindow.setFocusable(true);popupWindow.setBackgroundDrawable(new BitmapDrawable());popupWindow.setAnimationStyle(R.style.pop_animation);}}

主布局文件

<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”xmlns:tools=”http://schemas.android.com/tools”android:layout_width=”match_parent”android:layout_height=”match_parent”android:paddingBottom=”@dimen/activity_vertical_margin”android:paddingLeft=”@dimen/activity_horizontal_margin”android:paddingRight=”@dimen/activity_horizontal_margin”android:paddingTop=”@dimen/activity_vertical_margin”tools:context=”com.wjj.popupwindowdemo.MainActivity”android:id=”@+id/root”android:background=”#DEB887″><Buttonandroid:id=”@+id/showPopupWindow”android:layout_width=”wrap_content”android:layout_height=”wrap_content”android:text=”showPopupWindow”android:background=”#40E0D0″/></LinearLayout>

弹出内容的布局:

==”match_parent”android:orientation=”vertical” ><LinearLayout==”vertical” ><LinearLayout==”vertical”android:background=”@drawable/shape”><TextView====”16sp” /><LinearLayout=”#999999″ ></LinearLayout><TextView====”16sp” /><LinearLayout=”#999999″ ></LinearLayout><TextView====></RelativeLayout>

圆角的shape:xml

===”7dip” /> </shape>

动画效果(显示出来)

=”http://schemas.android.com/apk/res/android”android:shareInterpolator=”false”><translate=”300″/><alpha=”120″/> </set>接受失败等于回归真实的自我,

Android PopupWindow实现,类似于iOS的选择栏

相关文章:

你感兴趣的文章:

标签云: