欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

activity控制對(duì)話框風(fēng)格、顯示大小與位置

 更新時(shí)間:2016年12月20日 11:31:26   作者:小破孩123  
對(duì)于對(duì)話框風(fēng)格大家普遍使用PopupWindow,也有許多朋友開發(fā)設(shè)計(jì)時(shí)使用的是activity對(duì)話框方式,因此,本文對(duì)如何通過(guò)activity實(shí)現(xiàn)與PopupWindow相同的效果進(jìn)行詳細(xì)介紹,具有很好的參考價(jià)值,需要的朋友一起來(lái)看下吧

項(xiàng)目開發(fā)的需要,因?yàn)榈浆F(xiàn)在項(xiàng)目接近完工,用戶提出對(duì)條件篩選方式進(jìn)行修改,為做到最小的改動(dòng)實(shí)現(xiàn)用戶的需求,各種百度,對(duì)于對(duì)話框風(fēng)格大家普遍使用PopupWindow,但由于之前開發(fā)設(shè)計(jì)時(shí)使用的是activity對(duì)話框方式,所以今天就為大家介紹一下,如何通過(guò)activity實(shí)現(xiàn)與PopupWindow相同的效果,廢話不多講現(xiàn)在開始干貨。

實(shí)現(xiàn)對(duì)話框風(fēng)格的activity,我們需要在AndroidManifest.xml添加一句樣式聲明:

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

不過(guò)這樣的對(duì)話框風(fēng)格往往無(wú)法滿足我們的需要,顯示的效果不那么令人滿意,第一點(diǎn)就是如何控制對(duì)話框的大小

//窗口對(duì)齊屏幕寬度
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;//設(shè)置對(duì)話框置頂顯示
win.setAttributes(lp);

將這個(gè)控制語(yǔ)句添加在我們的對(duì)話框activity的onClick()方法中,這樣我們的對(duì)話框就可以寬度與屏幕一樣寬了,lp.gravity = Gravity.TOP;//設(shè)置對(duì)話框置頂顯示,android默認(rèn)對(duì)話框居中顯示,我們可以通過(guò)這句代碼設(shè)置對(duì)話框的顯示位置。

到這里是不是已經(jīng)達(dá)到你的滿意了呢?下面在給大家介紹一下,如何通過(guò)activity實(shí)現(xiàn)微信右上角點(diǎn)擊加號(hào)的顯示效果。做這個(gè)顯示效果,我們需要通過(guò)在布局文件中通過(guò)android:layout_marginTop="50dp"這樣來(lái)調(diào)整對(duì)話框的位置,Android默認(rèn)彈出框效果非常難看,為了達(dá)到更好的顯示效果,我們這里添加一個(gè)顯示的動(dòng)畫效果:

進(jìn)入動(dòng)畫:

<?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>

退出動(dòng)畫:

<?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動(dòng)畫文件一般置于res的anim文件夾下,默認(rèn)該文件夾不存在,需要我們手動(dòng)添加。

下面我們需要把我們的動(dòng)畫添加的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>
  <!-- 沒(méi)有標(biāo)題 -->
  <style name="notitle" parent="AppBaseTheme">
     <item name="android:windowNoTitle">true</item>
  </style>
  <!-- 類似對(duì)話框效果 -->
  <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>

最后我們需要修改一下我們?cè)贏ndroidManifest.xml文件中的聲明:

android:theme="@style/MyDialogTopRight"

到這里我們就完美實(shí)現(xiàn)了activity的對(duì)話框風(fēng)格顯示。

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論