簡體   English   中英

Android:創建的彈出窗口未在設備上清晰顯示

[英]Android:Created popup window is not displaying clearly on the device

我使用 xml 布局文件創建了一個彈出窗口。 我用它來顯示單擊按鈕時的說明。

這是我的彈出窗口代碼,

popup_window.xml

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

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/pop_txtView1"
        android:layout_marginTop="50dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:text="Theme"
        android:textSize="20sp"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/pop_txtView2"
        android:layout_marginTop="24dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:text="Full"
        android:textSize="20sp"/>


    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/pop_txtView3"
        android:layout_marginTop="24dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:text="@string/full_detail"
        android:textSize="16sp"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/pop_txtView4"
        android:layout_marginTop="48dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:text="Lite"
        android:textSize="20sp"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/pop_txtView5"
        android:layout_marginTop="24dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:text="@string/lite_detail"
        android:textSize="16sp"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="40dp"
        android:layout_gravity="right">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/pop_txtView6"
            android:textSize="20sp"
            android:layout_weight="1"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/pop_txtView7"
            android:text="Cancel"
            android:layout_marginLeft="40dp"
            android:clickable="true"
            android:textSize="20sp"
            android:layout_weight="1"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/pop_txtView8"
            android:text="OK"
            android:layout_marginLeft="10dp"
            android:clickable="true"
            android:textSize="20sp"
            android:layout_weight="1"/>

    </LinearLayout>


</LinearLayout>

這就是我調用彈出窗口的方式,

private PopupWindow popupWindow;

@InjectView(R.id.ib_question)
ImageButton qestionImageButton;

@OnClick(R.id.ib_question)
public void showPopup(){

      try{
          LayoutInflater inflater = (LayoutInflater) ProfileUserActivity.this
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View layout = inflater.inflate(R.layout.popup_window,
                    (ViewGroup) findViewById(R.id.popup_layout));
          popupWindow = new PopupWindow(layout, 300, 370, true);
          popupWindow.showAtLocation(layout, Gravity.CENTER, 0, 0);

      }catch (Exception ex){
          ex.printStackTrace();
      }

}

當我單擊此圖像按鈕時,我無法將彈出窗口和活動分開。

下面的屏幕截圖讓您清楚地了解我的問題。

在此處輸入圖片說明

對此有任何想法嗎?

你必須這樣設置

LayoutInflater inflater = (LayoutInflater) ProfileUserActivity.this
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 View layout = inflater.inflate(R.layout.popup_window,null);
  popupWindow = new PopupWindow (layout ,ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
  popupWindow.showAtLocation(layout, Gravity.CENTER, 0, 0);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM