弹出错误的按钮不会显示所有按钮

时间:2019-05-07 09:05:40

标签: android

我正在尝试在此项目上创建一个简单的弹出窗口,虽然代码在某些设备上可以运行,但是在某些设备上似乎存在错误。

这是XML

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/popup_bg"
    android:gravity="center"
    android:orientation="vertical"
    android:padding="10dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Silakan pilih yang ingin di rating"
        android:textColor="#000" />

    <Button
        android:id="@+id/btn_atasan"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="3dp"
        android:layout_marginTop="5dp"
        android:background="@drawable/button_bg"
        android:text="Atasan"
        android:textColor="#fff" />

    <Button
        android:id="@+id/btn_sekawan"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="3dp"
        android:background="@drawable/button_bg"
        android:text="Sekawan"
        android:textColor="#fff" />

    <Button
        android:id="@+id/btn_bawahan"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="3dp"
        android:background="@drawable/button_bg"
        android:text="Bawahan"
        android:textColor="#fff" />

</LinearLayout>

这是片段上的Java代码

private void popUpRatingType() {

    //instantiate the popup.xml layout file
    LayoutInflater layoutInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View customView = layoutInflater.inflate(R.layout.popup_rate_karyawan, null);

    //casting buttons
    btnAtasan = customView.findViewById(R.id.btn_atasan);
    btnBawahan = customView.findViewById(R.id.btn_bawahan);
    btnSekawan = customView.findViewById(R.id.btn_sekawan);

    //instantiate popup window
    popupWindow = new PopupWindow(customView, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);

    //display the popup window
    popupWindow.showAtLocation(contentFrame, Gravity.CENTER, 0, 0);

删除外部点击弹出窗口

    // Removes default background.
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    // Closes the popup window when touch outside.
    popupWindow.setOutsideTouchable(true);
    popupWindow.setFocusable(true);
    popupWindow.update();
}

在某些设备上看起来还可以,就像这样:

enter image description here

但是我不知道在某些设备上(在牛轧糖上)看起来像这样:

enter image description here

1 个答案:

答案 0 :(得分:0)

 private void popUpRatingType() {

    //instantiate the popup.xml layout file
    LayoutInflater layoutInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View customView = layoutInflater.inflate(R.layout.item_temp, null);

    //casting buttons
    //instantiate popup window
    PopupWindow popupWindow = new PopupWindow(customView, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);

    //display the popup window
    popupWindow.showAtLocation(customView, Gravity.CENTER, 0, 0);
    popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    // Closes the popup window when touch outside.
    popupWindow.setOutsideTouchable(true);
    popupWindow.setFocusable(true);
    popupWindow.update();
}