首先,要为popupWindow 写一个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="wrap_content"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_max"
android:layout_marginRight="@dimen/margin_max"
android:background="@color/white"
android:orientation="vertical" >
<!-- main content -->
<TextView
android:id="@+id/diet_pop_tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_max"
android:text="@string/activity_aerobic"
android:textColor="@color/string_bgwhite_main"
android:textSize="@dimen/text_15" />
<!-- main content sub -->
<TextView
android:id="@+id/diet_pop_tv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/recipe_choose_exam"
android:layout_marginLeft="@dimen/margin_max"
android:textColor="@color/string_bgwhite_sub"
android:textSize="@dimen/text_15" />
<!-- second title -->
<TextView
android:id="@+id/diet_pop_tv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/diet_pop_title"
android:paddingLeft="@dimen/margin_max"
android:layout_marginLeft="@dimen/margin_max"
android:text="@string/activity_aerobic_content"
android:textColor="@color/white"
android:textSize="@dimen/text_15"
/>
<!-- second content -->
<TextView
android:id="@+id/diet_pop_tv4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_max"
android:text="@string/activity_aerobic_suggest"
android:textColor="@color/string_bgwhite_main"
android:textSize="@dimen/text_15" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:background="@drawable/popupshadow"
/>
</LinearLayout>
</LinearLayout>
---------然后---再代码中处理popupWindow,
// new popupwindow
View inflateView = getLayoutInflater().inflate(
R.layout.recipe_popwindow, null);//上面的xml文件,作为popupWindow的视图
mPopupWindow = new PopupWindow(inflateView, LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
mPopupWindow.setFocusable(false);
mPopupWindow.setOutsideTouchable(true);
mPopupWindow.setAnimationStyle(R.style.AnimationPreview);//为popupWindow设置进入,退出的动画效果
------下面配置进入退出的动画:
anim文件夹下,进入动画(由右下角进入,由小变大):
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<scale android:fromXScale=".1" android:toXScale="1.0"
android:fromYScale=".1" android:toYScale="1.0"
android:pivotX="100%p" android:pivotY="100%p"
android:duration="500"/>
<alpha android:fromAlpha="0" android:toAlpha="1.0"
android:duration="@android:integer/config_mediumAnimTime"/>
</set>
退出动画(向右下角退出,由大变小,变透明):
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator"
android:zAdjustment="top">
<scale android:fromXScale="1.0" android:toXScale=".5"
android:fromYScale="1.0" android:toYScale=".5"
android:pivotX="100%p" android:pivotY="100%p"
android:duration="@android:integer/config_mediumAnimTime" />
<alpha android:fromAlpha="1.0" android:toAlpha="0"
android:duration="@android:integer/config_m
补充:移动开发 , Android ,