国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

activity控制對話框風格、顯示大小與位置

2019-12-12 04:16:42
字體:
來源:轉載
供稿:網友

項目開發的需要,因為到現在項目接近完工,用戶提出對條件篩選方式進行修改,為做到最小的改動實現用戶的需求,各種百度,對于對話框風格大家普遍使用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的對話框風格顯示。

以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持武林網!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永泰县| 华宁县| 涟水县| 汝阳县| 凯里市| 九江县| 曲松县| 抚松县| 英山县| 芜湖县| 昂仁县| 龙门县| 兴隆县| 教育| 阿坝县| 乐业县| 化州市| 宜都市| 龙井市| 宿迁市| 黄浦区| 武穴市| 思南县| 略阳县| 阆中市| 农安县| 德化县| 汝城县| 醴陵市| 板桥市| 宜宾县| 天水市| 深州市| 新丰县| 吉安县| 思南县| 普兰县| 利辛县| 宣汉县| 房产| 兴山县|