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

iOS實現(xiàn)底部彈出PopupWindow效果 iOS改變背景透明效果

 更新時間:2017年07月11日 09:29:07   投稿:lijiao  
這篇文章主要為大家詳細介紹了iOS實現(xiàn)底部彈出PopupWindow效果,iOS改變背景透明效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下

底部彈出PopupWindow,背景變?yōu)榘胪该餍Ч捎脙煞N方式實現(xiàn)

先來看看運行效果圖

運行效果圖
運行效果圖

[方式一]實現(xiàn)從底部彈出PopupWindow

原理:定義一個高度為wrap_content的PopupWindow布局文件,根據(jù)屏幕底部的位置顯示在Bottom

1.首先定義一個高度為wrap_content的PopupWindow布局文件

<?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="wrap_content"
  android:gravity="center"
  android:padding="8dp"
  android:orientation="vertical" >

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical"
    android:background="@drawable/shape_info_bg">
    <TextView android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:padding="8dp"
      android:gravity="center"
      android:textColor="@color/theme_blue"
      android:text="拍照"/>
    <View android:layout_width="match_parent" 
      android:layout_height="0.2dp"
      android:background="@color/theme_blue"/>
    <TextView android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:padding="8dp"
      android:gravity="center"
      android:textColor="@color/theme_blue"
      android:text="相冊"/>
  </LinearLayout>

  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:padding="1dp">
    <Button
      android:id="@+id/btn_cancle"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:padding="8dp"
      android:textColor="@color/theme_blue"
      android:background="@drawable/shape_info_bg"
      android:text="取消" />
  </RelativeLayout>
</LinearLayout>

2.在PopupWindow所在的Activity根布局中聲明id(在彈出PopupWindow作為位置參考的相對View)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/root_main"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" 
  android:background="@color/white">

  <Button android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="底部彈出PopupWindow"
    android:onClick="openPop"/>

   <Button android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="半透明底部PopupWindow"
    android:onClick="openPop2"/>
</LinearLayout>

3.MainActivity中點擊按鈕彈出PopupWindow

/** 彈出底部對話框 */
public void openPop(View view) {
  View popView = LayoutInflater.from(mContext).inflate(
      R.layout.pop_bottom, null);
  View rootView = findViewById(R.id.root_main); // 當前頁面的根佈局
  final PopupWindow popupWindow = new PopupWindow(popView,    LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);

  setBackgroundAlpha(0.5f);//設置屏幕透明度

  popupWindow.setBackgroundDrawable(new BitmapDrawable());
  popupWindow.setFocusable(true);// 點擊空白處時,隱藏掉pop窗口
  // 顯示在根佈局的底部
  popupWindow.showAtLocation(rootView, Gravity.BOTTOM | Gravity.LEFT, 0,
      0);

}

4.設置背景變?yōu)榘胪该餍Ч?,由于PopupWindow中并未設置背景色,所以彈出時PopupWindow以外的部分顯示當前Acitivity的內(nèi)容,設置背景色原理通過設置當前Activity所在屏幕的透明度來達到背景透明的效果!在退出時popupWindow時,需要恢復屏幕原有透明度

popupWindow.setOnDismissListener(new OnDismissListener() {
      @Override
      public void onDismiss() {
        // popupWindow隱藏時恢復屏幕正常透明度
        setBackgroundAlpha(1.0f);
      }
    });
/**
 * 設置添加屏幕的背景透明度
 * 
 * @param bgAlpha
 *      屏幕透明度0.0-1.0 1表示完全不透明
 */
public void setBackgroundAlpha(float bgAlpha) {
  WindowManager.LayoutParams lp = ((Activity) mContext).getWindow()
      .getAttributes();
  lp.alpha = bgAlpha;
  ((Activity) mContext).getWindow().setAttributes(lp);
}

[方式二]全屏PopupWindow實現(xiàn)底部彈出,背景半透明

原理:彈出一個全屏popupWindow,高度為match_parent,將根布局的Gravity屬性設置bottom,根布局背景設置為一個半透明的顏色#36000000, 彈出時全屏的popupWindow半透明效果背景覆蓋了在Activity之上 給人感覺上是popupWindow彈出后,背景變成半透明

布局文件

<?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:padding="8dp"
  android:orientation="vertical" 
  android:background="#36000000"
  android:gravity="bottom">

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical"
    android:background="@drawable/shape_info_bg">
    <TextView android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:padding="8dp"
      android:gravity="center"
      android:textColor="@color/theme_blue"
      android:text="拍照"/>
    <View android:layout_width="match_parent" 
      android:layout_height="0.2dp"
      android:background="@color/theme_blue"/>
    <TextView android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:padding="8dp"
      android:gravity="center"
      android:textColor="@color/theme_blue"
      android:text="相冊"/>
  </LinearLayout>

  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:padding="1dp">
    <Button
      android:id="@+id/btn_cancle"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:padding="8dp"
      android:textColor="@color/theme_blue"
      android:background="@drawable/shape_info_bg"
      android:text="取消" />
  </RelativeLayout>
</LinearLayout>

彈出方法和方式一相似,不過不用再監(jiān)聽popupWindow的退出事件

/**
 * 彈出底部對話框,達到背景背景透明效果
 * 
 * 實現(xiàn)原理:彈出一個全屏popupWindow,將Gravity屬性設置bottom,根背景設置為一個半透明的顏色,
 * 彈出時popupWindow的半透明效果背景覆蓋了在Activity之上 給人感覺上是popupWindow彈出后,背景變成半透明
 */
public void openPop2(View view) {
  View popView = LayoutInflater.from(mContext).inflate(
      R.layout.pop_bottom_alpha, null);
  View rootView = findViewById(R.id.root_main); // 當前頁面的根佈局
  final PopupWindow popupWindow = new PopupWindow(popView,
      LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

  // 設置彈出動畫
  popupWindow.setAnimationStyle(R.style.AnimationFadeBottom);
  popupWindow.setBackgroundDrawable(new BitmapDrawable());
  // 顯示在根佈局的底部
  popupWindow.showAtLocation(rootView, Gravity.BOTTOM | Gravity.LEFT, 0,
      0);
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • iOS實現(xiàn)帶指引線的餅狀圖效果(不會重疊)

    iOS實現(xiàn)帶指引線的餅狀圖效果(不會重疊)

    餅狀圖對大家來說應該都不陌生,下面這篇文章主要給大家介紹了關于iOS實現(xiàn)帶指引線的餅狀圖效果(不會重疊)的相關資料,文章通過示例代碼介紹的非常詳細,需要的朋友可以參考借鑒,下面隨著小編來一起學習學習吧。
    2018-04-04
  • iOS如何固定UITableView中cell.imageView.image的圖片大小

    iOS如何固定UITableView中cell.imageView.image的圖片大小

    這篇文章主要給大家介紹了關于iOS如何固定UITableView中cell.imageView.image圖片大小的相關資料,文中通過示例代碼介紹的非常詳細,對各位iOS開發(fā)者們的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。
    2017-11-11
  • IOS 中runtime使用方法整理

    IOS 中runtime使用方法整理

    這篇文章主要介紹了IOS 中runtime使用方法整理的相關資料,需要的朋友可以參考下
    2017-03-03
  • iOS實現(xiàn)支持小數(shù)的星星評分組件實例代碼

    iOS實現(xiàn)支持小數(shù)的星星評分組件實例代碼

    程序中需要打分的功能,在網(wǎng)上找了幾個,都不是很滿意。所以自己動手實現(xiàn)了一個,下面這篇文章主要給大家介紹了關于利用iOS實現(xiàn)支持小數(shù)的星星評分組件的相關資料,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-08-08
  • iOS如何實現(xiàn)強制轉(zhuǎn)屏、強制橫屏和強制豎屏的實例代碼

    iOS如何實現(xiàn)強制轉(zhuǎn)屏、強制橫屏和強制豎屏的實例代碼

    本篇文章主要介紹了iOS如何實現(xiàn)強制轉(zhuǎn)屏、強制橫屏和強制豎屏的實例代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Flutter?模型動態(tài)化賦值研究分析

    Flutter?模型動態(tài)化賦值研究分析

    這篇文章主要為大家介紹了Flutter?模型動態(tài)化賦值研究分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-03-03
  • 混合棧跳轉(zhuǎn)導致Flutter頁面事件卡死問題解決

    混合棧跳轉(zhuǎn)導致Flutter頁面事件卡死問題解決

    這篇文章主要為大家介紹了混合棧跳轉(zhuǎn)導致Flutter頁面事件卡死問題解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-08-08
  • iOS UITableView 拖動排序?qū)崿F(xiàn)代碼

    iOS UITableView 拖動排序?qū)崿F(xiàn)代碼

    這篇文章主要為大家詳細介紹了iOS UITableView 拖動排序?qū)崿F(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • IOS 解決推送本地國際化 loc-key 本地化失敗的問題

    IOS 解決推送本地國際化 loc-key 本地化失敗的問題

    本文主要介紹IOS 推送國際化問題,在開發(fā) IOS 項目過程中對軟件的國際化有的項目需求是需要的,這里給大家一個示例,有需要的小伙伴可以參考下
    2016-07-07
  • iOS實現(xiàn)簡易鐘表

    iOS實現(xiàn)簡易鐘表

    這篇文章主要為大家詳細介紹了iOS實現(xiàn)簡易鐘表,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-02-02

最新評論

焦作市| 宁晋县| 高青县| 平舆县| 大英县| 册亨县| 平舆县| 疏勒县| 嘉兴市| 大渡口区| 深水埗区| 达孜县| 水富县| 明溪县| 阳城县| 博客| 青河县| 石首市| 四子王旗| 上饶市| 鹿泉市| 新野县| 成安县| 定西市| 鸡东县| 大荔县| 安泽县| 永兴县| 建始县| 内江市| 沂源县| 临泽县| 天水市| 万荣县| 正定县| 松潘县| 梓潼县| 团风县| 绥芬河市| 屏东县| 孝义市|