2017-06-12 131 views
-1

我希望能夠在我的TextView下面顯示我的PopupWindow。我遵循教程,仍然無法讓它顯示我想要的地方。如何在TextView下方顯示popupWindow

enter image description here

我想讓它顯示的密鑰(TextView中)下方。

我的XML佈局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
      android:id="@+id/layout_master" 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      tools:context="com.example.test.myview.MainActivity"> 


     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 


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

         <TextView 
          android:id="@+id/textView0" 
          android:layout_width="wrap_content" 
          android:layout_height="match_parent" 
          android:gravity="center" 
          android:layout_marginLeft="10dp" 
          android:text="Options" /> 

         <Spinner 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:id="@+id/tagSpinner" /> 
       </LinearLayout> 


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

         <TextView 
          android:id="@+id/textView1" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginLeft="10dp" 
          android:text="sampleTxt" /> 

         <EditText 
          android:id="@+id/tagKey" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_weight="1" 
          android:ems="10" 
          android:hint="Type me.."></EditText> 
       </LinearLayout> 



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

         <TextView 
          android:id="@+id/textView2" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginLeft="10dp" 
          android:text="value" /> 

         <EditText 
          android:id="@+id/tagval" 
          android:layout_width="0dp" 
          android:layout_height="wrap_content" 
          android:layout_weight="1" 
          android:ems="10" 
          android:hint="Enter value"/> 
       </LinearLayout> 

       <Button 
        android:text="Button" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:onClick="btnclick" 
        android:id="@+id/aaaa" /> 

     </LinearLayout> 

</LinearLayout> 

編輯:我也是,如果它被切斷屏幕不介意

+0

你是如何真正展示你的'PopupWindow'?分享代碼。 – azizbekian

+0

@ azizbekian @ bhandari,編輯:我發現這個問題,這是由於popupWindow的寬度造成的。寬度將Tip推向左側,使其遠離TextView。如果我將寬度設置爲較小的值,則會解決問題。 –

回答

0
Clicking the button in the main screen try the below code:- 

Button buttonAction; 
     final PopupWindow mPopupwindow; 
     LayoutInflater mInflater = (LayoutInflater) mActivity.getSystemService(mActivity.LAYOUT_INFLATER_SERVICE); 
     View mView = mInflater.inflate(R.layout.popup_layout,layouttext,false); 
     mPopupwindow = new PopupWindow(mView, 300, 300, true); 
     mPopupwindow.showAsDropDown(layouttext,0,5); 
     buttonAction = (Button) mView.findViewById(R.id.buttonAction); 
     buttonAction.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       mPopupwindow.dismiss(); 
      } 
     });