Android从下往上(动画)滑出窗口
CzTestActivity.java:
package com.weijie.user.activity; import android.app.Activity; import android.os.Bundle; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup.LayoutParams; import android.widget.PopupWindow; import android.widget.TextView; import com.weijie.user.R; public class CzTestActivity extends Activity { private TextView mybut = null; // 定义按钮 private PopupWindow popWin = null; // 弹出窗口 private View popView = null; // 保存弹出窗口布局 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.cztest_main); // 调用布局管理器 this.mybut = (TextView) super.findViewById(R.id.mybut); // 取得按钮 this.mybut.setOnClickListener(new OnClickListenerImpl()); // 设置事件类 } private class OnClickListenerImpl implements OnClickListener { @Override public void onClick(View view) { LayoutInflater inflater = LayoutInflater.from(CzTestActivity.this); // 取得LayoutInflater对象 CzTestActivity.this.popView = inflater.inflate( R.layout.cztest_popwin, null); // 读取布局管理器 CzTestActivity.this.popWin = new PopupWindow(popView, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, true); // 实例化PopupWindow // 设置PopupWindow的弹出和消失效果 CzTestActivity.this.popWin .setAnimationStyle(R.style.popupAnimation); CzTestActivity.this.popWin.showAtLocation( CzTestActivity.this.mybut, Gravity.BOTTOM, 0, 0); // 显示弹出窗口 } } }
cztest_main.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/mybut" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="测试按钮" /> </LinearLayout>
cztest_popwin.xml:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" > <View android:id="@+id/transparent" android:layout_width="fill_parent" android:layout_height="15dp" android:background="#00ffffff" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/transparent" android:background="#ffffff" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:padding="5dp" android:text="性别修改" android:textColor="#000000" android:textSize="18sp" /> <View android:layout_width="fill_parent" android:layout_height="1px" android:background="#000000" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:padding="5dp" android:text="男" android:textColor="#000000" /> <View android:layout_width="fill_parent" android:layout_height="1px" android:background="#000000" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:padding="5dp" android:text="女" android:textColor="#000000" /> </LinearLayout> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:src="@drawable/popwin_close" /> </RelativeLayout>
<style name="popupAnimation" parent="android:Animation"> <item name="android:windowEnterAnimation">@anim/pop_in</item> <item name="android:windowExitAnimation">@anim/pop_out</item> </style>
pop_in.xml:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromYDelta="80%p" android:toYDelta="0" android:duration="1500" /> </set>
pop_out.xml:
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromYDelta="0" android:toYDelta="80%p" android:duration="1500" /> </set>
注:下面附上从右往左的动画代码:
//values/styles.xml <resources> <style name="mystyle" parent="android:Animation"> <item name="@android:windowEnterAnimation">@anim/dialog_enter</item> <!--进入时的动画 --> <item name="@android:windowExitAnimation">@anim/dialog_exit</item> <!-- 退出时的动画 --> </style> </resources> //anim/dialog_enter.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <!-- %p指相对于父容器 android:fromYDelta="100%p" android:toXDelta="100%p"--> <translate android:duration="600" android:fromXDelta="100%p" /> </set> //anim/dialog_exit.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <!-- //持续时间 --> <translate android:duration="600" android:toXDelta="100%" /> </set>
相关推荐
huha 2020-10-16
xfcyhades 2020-11-20
sgafdsg 2020-11-04
Michael 2020-11-03
fengyeezju 2020-10-14
ziyexiaoxiao 2020-10-14
业余架构师 2020-10-09
OuNuo0 2020-09-29
moses 2020-09-22
Angelia 2020-09-11
qinxu 2020-09-10
刘炳昭 2020-09-10
Nostalgiachild 2020-09-07
Nostalgiachild 2020-08-17
leavesC 2020-08-14
一青年 2020-08-13
AndroidAiStudy 2020-08-07
ydc0 2020-07-30
绿豆饼 2020-07-28