Почему не появляется мое Android PopupWindow? - PullRequest
0 голосов
/ 09 марта 2019

Я изо всех сил пытался выяснить, почему мое PopupWindow отказывается появляться. Я раздул его вид и убедился, что он отображается в правильном контейнере вида.

Есть идеи, почему окно не появляется?

Вот код, который я вызываю в упражнении, где я хочу всплывающее окно:

    LinearLayout linearLayout = findViewById(R.id.webLinLayout);
    LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
    ViewGroup container = (ViewGroup) inflater.inflate(R.layout.activity_popup_window, null);
    boolean focusable = false;
    PopupWindow popupWindow = new PopupWindow(container, 500, 500, focusable);
    popupWindow.showAtLocation(linearLayout, Gravity.CENTER, 0, 0);

XML-файл для моего макета активности:

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

    <EditText
        android:id="@+id/imgSearchBar"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:maxLines="1"
        android:textAlignment="textStart"
        android:hint="Search for an image">
    </EditText>

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:padding="15dp"
        android:clickable="true">
    </android.support.v7.widget.CardView>

</LinearLayout>

А вот мой макет всплывающего окна:

    <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <TextView
        android:id="@+id/loadingMsg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:text="Fetching your images..."
        android:textSize="48sp"/>

    <android.support.v4.widget.ContentLoadingProgressBar
        android:layout_width="300dp"
        android:layout_height="300dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/loadingMsg" />

</android.support.constraint.ConstraintLayout>

1 Ответ

0 голосов
/ 09 марта 2019

попробуйте это:

final LinearLayout linearLayout = findViewById(R.id.webLinLayout);

LayoutInflater inflater =
        (LayoutInflater)
                getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);

final ViewGroup container =
        (ViewGroup) inflater.inflate(R.layout.activity_popup_window, null);

boolean focusable = false;

final PopupWindow popupWindow = new PopupWindow(container, 500, 500, focusable);
linearLayout.post(new Runnable() {
    public void run() {
        popupWindow.showAtLocation(linearLayout, Gravity.CENTER, 0, 0);
    }
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...