展会信息港展会大全

popupWindow的使用心得
来源:互联网   发布日期:2015-10-13 07:31:31   浏览:1482次  

导读:首先,要为popupWindow 写一个xml配置文件:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:androi...

首先,要为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_mediumAnimTime"/>

</set>

--------在styles文件夹下配置style:

<style name="AnimationPreview">

<item name="android:windowEnterAnimation">@anim/zoomin</item>

<item name="android:windowExitAnimation">@anim/zoomout</item>

</style>

-------最后在代码中设置popupWindow进入退出的判定:

public void openMenu(View v) {

// System.out.println(view.getId() + "-----id--" + view.getBottom()

// + "bottom-----view" + view.getTop());

if (!flag) {//flag初始化为false;

// set position

// mPopupWindow.showAtLocation(view, Gravity.LEFT, 0, 0);

mPopupWindow.showAsDropDown(v, 0, 0);

// view.findViewById(R.id.diet_sugget_ka).setVisibility(View.INVISIBLE);

flag = true;

} else {

mPopupWindow.dismiss();

flag = false;

}

}

赞助本站

人工智能实验室

相关热词: android开发 教程

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港