詳しい使用PopupWindow

非常にお勧めの記事:ようこそお気に入り
のAndroidドライシェア

5分、毎日10時、あなたと生涯学習を読んで、ここでのAndroidのプログラマです

この資料に記載されているAndroidこの記事を読んで知識の開発の一部を、次のことを刈り取ります。

  1. PopupWindowの継承
  2. 使用PopupWindow
  3. PopupWindow PopupWindowの下を達成

PopupWindow可能であるActivity上記のいずれかの表示Viewを制御します。Android効果との定期的な使用、Dialogディスプレイの位置は、ディスプレイの底部として、制御することができることを除いて同様の効果。

はじめに1. PopupWindow

PopupWindowの継承次のように:

java.lang.Object
   ↳
     android.widget.PopupWindow

2.

主に、それが呼び出しPopWindowによってコンストラクタ変換し、次に具体的に参照して、いずれかを達成するために、渡さソースは次のように、ソースパスは次のとおりです。LayoutInflaterLayoutViewViewPopupWindowframework/base/core/java/android/widget/PopupWindow.java

PopWindows共通メソッドとコンストラクタ

3.下PopupWindowの実現

    1. PopupWindow結果を達成

結果を達成するためPopwindowボトム

    1. PopWindow実装クラス
public class PopWindowMethods extends Activity {
    private View mPopView;
    private PopupWindow mPopupWindow;
    private Button btn_pop_ok;
    private Button btn_pop_cancel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_popwindow);

        InitPopWindow();
        InitView();
        InitClick();
    }

    /**
     * 
     */
    private void InitClick() {
        // TODO Auto-generated method stub
        btn_pop_ok.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplicationContext(), "ok", 0).show();
            }
        });

        btn_pop_cancel.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplicationContext(), "cancel", 0).show();
            }
        });
    }

    /**
     * 
     */
    private void InitPopWindow() {
        // TODO Auto-generated method stub
        // 将布局文件转换成View对象,popupview 内容视图
        mPopView = getLayoutInflater().inflate(R.layout.popwindow_layout, null);
        // 将转换的View放置到 新建一个popuwindow对象中
        mPopupWindow = new PopupWindow(mPopView,
                LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        // 点击popuwindow外让其消失
        mPopupWindow.setOutsideTouchable(true);
        // mpopupWindow.setBackgroundDrawable(background);

    }

    /**
     * 
     */
    private void InitView() {
        btn_pop_ok = (Button) mPopView.findViewById(R.id.btn_pop_ok);
        btn_pop_cancel = (Button) mPopView.findViewById(R.id.btn_pop_cancel);

    }

    @SuppressLint("NewApi")
    public void ShowPopWindow(View view) {
        if (mPopupWindow.isShowing()) {
            mPopupWindow.dismiss();
        } else {
            // 设置PopupWindow 显示的形式 底部或者下拉等
            // 在某个位置显示
            mPopupWindow.showAtLocation(mPopView, Gravity.BOTTOM, 0, 30);
            // 作为下拉视图显示
            // mPopupWindow.showAsDropDown(mPopView, Gravity.CENTER, 200, 300);
        }

        // Toast.makeText(
        // getApplicationContext(),
        // "Launcher:"
        // + PackageUtils.isLauncherAPK(getApplicationContext(),
        // "com.miui.home"),
        // 0).show();
    }
}
    1. PopupWindowレイアウト
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:layout_marginTop="16dp"
    android:background="@drawable/popwindow_bg" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/tv_pop_tittle"
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:gravity="center"
            android:text="PopWindow Tittle" />

        <TextView
            android:id="@+id/tv_pop_content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="left|center_horizontal"
            android:padding="20dp"
            android:text="是否要退出Popwindows ? " />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_margin="3dp"
            android:background="@color/white_line" />

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

            <Button
                android:id="@+id/btn_pop_ok"
                android:layout_width="0dp"
                android:layout_height="45dp"
                android:layout_marginBottom="10dp"
                android:layout_marginLeft="10dp"
                android:layout_marginTop="10dp"
                android:layout_weight="1"
                android:background="@drawable/custom_btn_white_selector"
                android:gravity="center"
                android:text="OK" />

            <Button
                android:id="@+id/btn_pop_cancel"
                android:layout_width="0dp"
                android:layout_height="45dp"
                android:layout_margin="10dp"
                android:layout_marginBottom="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                android:layout_weight="1"
                android:background="@drawable/custom_btn_white_selector"
                android:gravity="center"
                android:text="Cancel" />
        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

この時点で、基本的なエンドを使用することをPopWindow。

間違った場所、あなたの提案や修正を歓迎している場合これまでのところ、本明細書に、これは、終了しました。同時に、あなたの注意を楽しみにして、お読みいただきありがとうございました、ありがとうございました!

マイクロチャネル国民の関心番号:プログラマーアンドロイド、福祉を受けます

おすすめ

転載: www.cnblogs.com/wangjie1990/p/11310831.html