发布于 2017-01-04 07:23:50 | 79 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Android移动端操作系统

Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。


对于对话框风格大家普遍使用PopupWindow,也有许多朋友开发设计时使用的是activity对话框方式,因此,本文对如何通过activity实现与PopupWindow相同的效果进行详细介绍,具有很好的参考价值,需要的朋友一起来看下吧

项目开发的需要,因为到现在项目接近完工,用户提出对条件筛选方式进行修改,为做到最小的改动实现用户的需求,各种百度,对于对话框风格大家普遍使用PopupWindow,但由于之前开发设计时使用的是activity对话框方式,所以今天就为大家介绍一下,如何通过activity实现与PopupWindow相同的效果,废话不多讲现在开始干货。

实现对话框风格的activity,我们需要在AndroidManifest.xml添加一句样式声明:


<activity
  android:name=".product.MyselfPayProduct"
  android:screenOrientation="portrait"
  android:theme="@android:style/Theme.Dialog" >

不过这样的对话框风格往往无法满足我们的需要,显示的效果不那么令人满意,第一点就是如何控制对话框的大小


//窗口对齐屏幕宽度
Window win = this.getWindow();
win.getDecorView().setPadding(0, 0, 0, 0);
WindowManager.LayoutParams lp = win.getAttributes();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.TOP;//设置对话框置顶显示
win.setAttributes(lp);

将这个控制语句添加在我们的对话框activity的onClick()方法中,这样我们的对话框就可以宽度与屏幕一样宽了,lp.gravity = Gravity.TOP;//设置对话框置顶显示,android默认对话框居中显示,我们可以通过这句代码设置对话框的显示位置。

到这里是不是已经达到你的满意了呢?下面在给大家介绍一下,如何通过activity实现微信右上角点击加号的显示效果。做这个显示效果,我们需要通过在布局文件中通过android:layout_marginTop="50dp"这样来调整对话框的位置,Android默认弹出框效果非常难看,为了达到更好的显示效果,我们这里添加一个显示的动画效果:

进入动画:


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
  <scale
    android:fromXScale="1.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:toXScale="1.0" 
    android:fromYScale="0.0"
    android:toYScale="1.0"
    android:duration="200"
    android:pivotX="0"
    android:pivotY="10%"
    />
</set>

退出动画:


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
  <scale
    android:fromXScale="1.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
    android:toXScale="1.0" 
    android:fromYScale="1.0"
    android:toYScale="0.0"
    android:duration="200"
    android:pivotX="0"
    android:pivotY="10%"
    />
</set>

android动画文件一般置于res的anim文件夹下,默认该文件夹不存在,需要我们手动添加。

下面我们需要把我们的动画添加的android的样式文件:style.xml


<resources>
  <!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
  -->
  <style name="AppBaseTheme" parent="android:Theme.Light">
    <!--
      Theme customizations available in newer API levels can go in
      res/values-vXX/styles.xml, while customizations related to
      backward-compatibility can go here.
    -->
  </style>
  <!-- Application theme. -->
  <style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
  </style>
  <!-- 没有标题 -->
  <style name="notitle" parent="AppBaseTheme">
     <item name="android:windowNoTitle">true</item>
  </style>
  <!-- 类似对话框效果 -->
  <style name="MyDialogTopRight"> 
    <item name="android:windowBackground">@android:color/transparent</item> 
    <item name="android:windowIsTranslucent">true</item> 
    <item name="android:windowNoTitle">true</item> 
    <item name="android:windowAnimationStyle">@style/Anim_scale</item> 
  </style> 
   <style name="Anim_scale" parent="@android:style/Animation.Activity">
    <item name="android:activityOpenEnterAnimation">@anim/scale_in</item>
    <item name="android:activityOpenExitAnimation">@anim/scale_out</item>
    <item name="android:activityCloseEnterAnimation">@anim/scale_in</item>
    <item name="android:activityCloseExitAnimation">@anim/scale_out</item>
  </style>
</resources>

最后我们需要修改一下我们在AndroidManifest.xml文件中的声明:

android:theme="@style/MyDialogTopRight"

到这里我们就完美实现了activity的对话框风格显示。

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持PHPERZ!



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务