为什么我的弹出窗口没有显示?

时间:2014-05-19 14:11:44

标签: java android android-layout android-popupwindow

我有这个班级

public class ShareTooltip extends PopupWindow {

  public ShareTooltip(Context context, ViewGroup rootView) {
    super();
    this.mContext = context;
    this.mParentRoot = rootView;
    this.mViewToPointAt = mParentRoot.findViewById(R.id.bottomBarFollowers);

    LayoutInflater inflater =
        (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mPopUpRoot = (LinearLayout) inflater.inflate(R.layout.tooltip_share, null);
    setContentView(mPopUpRoot);
  }


  // The method that displays the popup.
  public void showPopup() {
    mPopUpRoot.setVisibility(View.VISIBLE);
    mPopUpRoot.bringToFront();

    showAtLocation(mParentRoot, Gravity.NO_GRAVITY, 10, 10);
}

}

我正在呼叫showPopup(),但我没有看到弹出窗口。

我应该寻找什么?

这是我的xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/root_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
<!-- 
    android:background="#2278E700">
 -->
    <LinearLayout
        android:id="@+id/tooltip_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/tip_tool_top_left"
        android:gravity="top|left"
        android:orientation="horizontal"
        android:layout_marginTop="0dp"
        android:paddingBottom="20dp"
        android:paddingTop="10dp"
        android:paddingLeft="0dp"
        android:paddingRight="25dp" >

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

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginRight="10dp"
                android:layout_marginLeft="10dp"
                android:src="@drawable/tip_tool_icon_light_bulb" />
        </LinearLayout>
    </LinearLayout>
</FrameLayout>

更新

我也试过这个但没有成功:

LayoutInflater inflater =
    (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

LinearLayout viewGroup = (LinearLayout) mContext.findViewById(R.id.tooltip_layout);


mPopUpRoot = (LinearLayout) inflater.inflate(R.layout.tooltip_share, viewGroup);
setContentView(mPopUpRoot);

0 个答案:

没有答案