最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

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

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

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

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

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

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

進(jìn)入動畫:

<?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文件夾下,默認(rèn)該文件夾不存在,需要我們手動添加。

下面我們需要把我們的動畫添加的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>
  <!-- 沒有標(biāo)題 -->
  <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"

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

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

相關(guān)文章

最新評論

青川县| 龙川县| 渝中区| 观塘区| 弋阳县| 威海市| 墨江| 巴青县| 盐城市| 铁岭市| 习水县| 施甸县| 黎川县| 苏尼特左旗| 柳林县| 景洪市| 修武县| 江油市| 额敏县| 济南市| 隆子县| 淮安市| 达拉特旗| 都兰县| 大安市| 桑植县| 蕉岭县| 榆中县| 秀山| 海门市| 临西县| 古浪县| 天柱县| 刚察县| 防城港市| 福州市| 平顶山市| 连云港市| 嘉善县| 金川县| 常熟市|