1. 程式人生 > >android popupwindow從下彈出,顯示在某控制元件上方

android popupwindow從下彈出,顯示在某控制元件上方

popupwindow彈出時從下往上,隱藏時從上往下,並且顯示在指定控制元件上方
View inflate = LayoutInflater.from(getContext()).inflate(R.layout.popupwindow_shop, null);
                LinearLayout pop_del = inflate.findViewById(R.id.pop_shop_delete);
                ListView lst = inflate.findViewById(R.id.pop_shop_lst);

                window = new PopupWindow(inflate, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);
                window.setAnimationStyle(R.style.pop_shop_anim);
                // 例項化一個ColorDrawable顏色為半透明
                ColorDrawable dw = new ColorDrawable(0xb0000000);
                window.setBackgroundDrawable(dw);

                window.setOutsideTouchable(true);
                showUp(inflate);
                window.update();
private void showUp(View v) {
        v.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        int measuredHeight = v.getMeasuredHeight();
        int[] location = new int[2];
        linear.getLocationOnScreen(location);
        window.showAtLocation(linear, Gravity.NO_GRAVITY, 0, location[1] - measuredHeight);
    }
popupwindow_shop.xml佈局檔案:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#bfbfbf"
        android:orientation="horizontal">

        <LinearLayout
            android:id="@+id/pop_shop_delete"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/px10_dp"
            android:layout_marginLeft="@dimen/px20_dp"
            android:layout_marginTop="@dimen/px10_dp"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginRight="@dimen/px10_dp"
                android:src="@drawable/lajixiang" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/qingkong"
                android:textSize="@dimen/px20_sp"
                android:textColor="#000000"/>
        </LinearLayout>
    </LinearLayout>

    <ListView
        android:id="@+id/pop_shop_lst"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"></ListView>
</LinearLayout>

動畫:(在res下建立名為anim的資料夾,在anim資料夾下建立檔案)

pop_show

        當值設定為"50"時,表示使用絕對位置定位

        當值設定為"50%"時,表示使用相對於控制元件本身的一半定位

        當值設定為"50%P"時,表示使用相對於父控制元件的一半定位

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="1000"
        android:fromYDelta="100%p"
        android:toYDelta="0" />

    <alpha
        android:duration="1000"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />
</set>
pop_hidden
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="1000"
        android:fromYDelta="0"
        android:toYDelta="50%p" />

    <alpha
        android:duration="1000"
        android:fromAlpha="1.0"
        android:toAlpha="0.0" />
</set>

在values-styles下新增

<style name="pop_shop_anim">
        <!-- 顯示 -->
        <item name="android:windowEnterAnimation">@anim/pop_show</item>
        <!-- 消失 -->
        <item name="android:windowExitAnimation">@anim/pop_hidden</item>
    </style>

相關推薦

android popupwindow顯示控制元件上方

popupwindow彈出時從下往上,隱藏時從上往下,並且顯示在指定控制元件上方View inflate = LayoutInflater.from(getContext()).inflate(R.layout.popupwindow_shop, null);

Android實現底部Dialog(和PopWindow實現的效果一樣)

上菜,不,上圖:       相信上圖的效果,大家在android 裝置中經常碰到.有時候進行分享操作的時候-----要求從從底部自下而上彈出.上圖中的效果**既可以通過自定義Dialog實現也可以通過自定義PopWindow來實現.**關於popWindow

透明Activity底部除去頂部黑線和系統狀態列

這幾天發現透明Activity從底部彈出的時候,在5.0以下的安卓版本中,在彈出的過程中,頂部會有一條黑線;而在5.0的安卓系統中,發現系統狀態列居然也隨著Activity從底部彈出來了,看著非常不美觀啊。 5.0以下的安卓系統: 5.0版本的安卓系統:

Android實現底部的Dialog

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xml

仿IOS ActionSheet控制元件Dialog

使Dialog從下彈出,無非就是控制控制元件彈出的初始位置和彈出後的位置,其步驟和重寫Dialog類似,不過要重寫Dialog的預設樣式 <style name="ActionSheet" parent="@android:style/Theme.Dialog"

Android PopupWindow 的方法 & 視窗方法

本人小菜一個。目前只見過兩種彈出框的實現方式,第一種是最常見的PopupWindow,第二種也就是Activity的方式是前幾天才見識過。感覺很霸氣哦。沒想到,activity也可以做偽視窗。  先貼上最常見的方法,主要講activity的方法。  一、彈出PopupWindow  複製程式碼程式碼如下:

Android 框LemonBubble提示控制元件

簡介:這是一個完全Made in China的炫酷彈出指示層Android版本(-_-#意思就是還有iOS的),他能讓你快速的自定義任何樣式的彈出框 最新更新記錄: 捕捉了LemonBubble.forceHide()中的空指標異常,保證開發者在onDestroy

Android軟鍵盤時把佈局控制元件頂上去的解決方法

在有的佈局中,軟體盤輸入內容時,會把底下的佈局控制元件給頂上去。如何不讓其被頂上去呢?android:windowSoftInputMode activity主視窗與軟體盤的互動模式,可以用來避免輸入法面板遮擋問題,Android1.5後的一個新特性。 它的設定必須

使用Delphi顯示ActiveX控制元件的屬性頁方法

unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, OleCtrls, MSCommLib_TLB, St

Android PopupWindow實現頂部拉選單左、中、右

          本例項的自定義下拉選單主要是繼承PopupWindow類來實現的彈出窗體,各種佈局效果可以根據自己定義設計。彈出的動畫效果主要用到了translate、alpha、scale,具體實現步驟如下:          先上效果圖如下:左邊下拉選單、中間下拉選

iOS 鍵盤處理(改變鍵盤為完成鍵)UITextField鍵盤顯示隱藏

框架 設置代理 res bool sea boa rst frame 技術分享 很多時候用到UITextField時,處理鍵盤是一個很棘手的問題。 問題一:如何隱藏鍵盤? 方案1.改變鍵盤右下角的換行(enter)鍵為完成鍵,後實現代理方法鍵盤自動回彈 keyBoard

Android軟鍵盤覆蓋h5頁面輸入框問題

問題 過多 繼承 col 鍵盤 代碼 chrom 技術 fff 之前我們在使用vue進行 h5 表單錄入的過程中,遇到了Android軟鍵盤彈出,覆蓋 h5頁面 輸入框 問題,在此進行回顧並分享給大家: 系統:Android 條件:當輸入框在可視區底部或者偏下的位置 觸發

PopupWindow簡單實用小例子之內容顯示框(一)

我們要做的功能是點選按鈕彈出一個內容框之後點選彈出的對話方塊的內容將內容顯示在輸入框中先來看下效果圖 利用PopupWindow實現彈出的內容框,PopupWindow構造可以理解為ListView+TextView,ListView是整個顯示內容的框架,而我們要顯示的內容是用TextVi

VS程式設計C#顯示欄位資訊分行增加空格的一種方法。

‘\n’是換行; “    ”是填充的空格; aaaa是程式中定義的 int  資料,也可以是其它型別的資料; 注意各自的符號。最後一項可以不要,  MessageBox.Show("資料匯入完成"

Android軟鍵盤介面整體上移終極解決方式

今天在應測試要求:軟鍵盤彈出不能遮擋EditView,在網上找了各種方案,基本都不行,比如: android:windowSoftInputMode=“adjustResize|stateHidden” 可能在一般的頁面是可以用吧。 下面來說一個曲線救國的方案,

popupwindow往上滑

mPopWindow.setAnimationStyle(R.style.anim_pop_bottombar); styles.xml: <style name="anim_po

Android開發】動畫PopupWindow並使背景變暗

我們在平常的android應用開發過程中,當應用資料太多太繁雜時,通常都會通過分類篩選讓使用者更好的找到自己想要的資訊。因此利用PopupWindow或Dialog讓使用者快速選擇定位是一個很好的選擇。如我們想在美團上查詢附近有什麼電影院時: 點選按鈕彈出

顯示2秒後自動消失

        jQuery(document).ready(function($) {             $('.theme-login').click(function(){                 $('.theme-popover-mask').fadeIn(100);         

Android軟鍵盤介面整體上移

在做搜尋功能的時候,點選搜尋框,搜尋框獲取焦點,鍵盤彈出;現在問題出來了,android軟鍵盤彈出的時候,android整個介面上移,佈局被擠壓,很難看;要解決這個問題,我們需要用到 windowSoftInputMode屬性;參考:http://blog.csdn.net

popupwindow父類背景變暗問題

</pre><p>(1)彈出popupwindow時:</p><p><pre name="code" class="java">WindowManager.LayoutParams lp = getWindow()