2015-05-02 14 views
7

Ich habe eine Ansicht, in der ich ein PopupWindow erstellen. In diesem PopupWindow habe ich ein Textfeld (EditText). Wenn Sie klicken, um den Text zu bearbeiten, öffnet sich die Tastatur und die gesamte Ansicht wird geöffnet, aber der obere Teil der Ansicht wird unter der Ansicht der Aktionsleiste reibungslos. So weit, ist es gut.Android- Hinzufügen von Ansicht zu Layout Layout Layout vor ActionBar

Ich habe eine leere GridView ohne weitere Konfiguration zum PopupWindow, und jetzt das gleiche Szenario passiert, aber das ganze obere Teil der Ansicht geht auf glatte der Aktionsleiste Ansicht und nicht jetzt hinzugefügt (das Popup wird Ein Durcheinander, wenn die Tastatur verschwindet, ändert sich der Popup-Standort für einige Sekunden und es gibt "Reste" von der Tastatur für eine Sekunde. Es passiert auch mit ListView.

Ich möchte den oberen Teil der Ansicht unter die "ActionBar" reibungslos gehen, wie es sollte.

Irgendwelche Ideen?

UPDATE: Durch das Hinzufügen der GridView programmatisch löste ich es teilweise auf ein paar Geräten, aber auf einigen Geräten ist es immer noch passiert.

Anzeige der popupwindow:

pView=inflater.inflate(R.layout.activity_packbuild, (ViewGroup)mainActivity.findViewById(R.layout.activity_main)); 

pw = new PopupWindow(
      pView, 
      ma.f.getView().getMeasuredWidth(), 
      ma.f.getView().getMeasuredHeight(), 
      true); 

pw.showAtLocation(mainActivity.getWindow().getDecorView().findViewById(android.R.id.content), Gravity.BOTTOM, 0, 0); 

GUT:

enter image description here

BAD:

enter image description here

Layout:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:id="@+id/lID"> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/rID" 
    android:background="@drawable/back5"> 


    <ImageView 
     android:layout_width="125px" 
     android:layout_height="200px" 
     android:id="@+id/mImageView" 
     android:background="@drawable/com_facebook_picker_default_separator_color" 
     android:layout_alignParentTop="true" 
     android:layout_weight="1" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="300dp" /> 

    <EditText 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/editText" 
     android:layout_below="@+id/mImageView" 
     android:layout_marginTop="22dp" 
     android:layout_toRightOf="@+id/lButton" 
     android:layout_toLeftOf="@+id/rButton" /> 

    <ImageView 
     android:layout_width="125px" 
     android:layout_height="200px" 
     android:id="@+id/imageViewRR" 
     android:background="@drawable/com_facebook_picker_default_separator_color" 
     android:layout_alignTop="@+id/mImageView" 
     android:layout_toRightOf="@+id/mImageView" 
     android:layout_marginLeft="20dp" /> 

    <ImageView 
     android:layout_width="125px" 
     android:layout_height="200px" 
     android:id="@+id/imageViewLL" 
     android:background="@drawable/com_facebook_picker_default_separator_color" 
     android:layout_alignTop="@+id/mImageView" 
     android:layout_toLeftOf="@+id/mImageView" 
     android:layout_marginRight="20dp" /> 

    <ImageButton 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:id="@+id/lButton" 
     android:layout_below="@+id/editText" 
     android:layout_alignLeft="@+id/imageViewLL" 
     android:layout_alignStart="@+id/imageViewLL" /> 

    <ImageButton 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:id="@+id/rButton" 
     android:layout_alignTop="@+id/lButton" 
     android:layout_alignRight="@+id/imageViewRR" 
     android:layout_alignEnd="@+id/imageViewRR" 
     android:layout_marginTop="5dp" /> 

    <ImageButton 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:id="@+id/picButton" 
     android:layout_alignTop="@+id/galleryButton" 
     android:layout_alignLeft="@+id/editText" 
     android:layout_alignStart="@+id/editText" 
     android:background="@drawable/camera2" /> 

    <ImageButton 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:id="@+id/videoButton" 
     android:background="@drawable/video" 
     android:layout_alignTop="@+id/galleryButton" 
     android:layout_centerHorizontal="true" /> 

    <ImageView 
     android:layout_width="125px" 
     android:layout_height="200px" 
     android:id="@+id/imageViewR" 
     android:background="@drawable/com_facebook_picker_default_separator_color" 
     android:layout_above="@+id/editText" 
     android:layout_alignRight="@+id/sendButon" 
     android:layout_alignEnd="@+id/sendButon" /> 

    <ImageView 
     android:layout_width="125px" 
     android:layout_height="200px" 
     android:id="@+id/imageViewL" 
     android:background="@drawable/com_facebook_picker_default_separator_color" 
     android:layout_alignTop="@+id/mImageView" 
     android:layout_alignLeft="@+id/editText" /> 

    <ImageButton 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:id="@+id/galleryButton" 
     android:background="@drawable/gallery" 
     android:layout_alignTop="@+id/rButton" 
     android:layout_alignRight="@+id/imageViewR" /> 

    <ImageButton 
     android:layout_width="100px" 
     android:layout_height="100px" 
     android:id="@+id/toButton" 
     android:layout_above="@+id/imageViewR" 
     android:layout_alignLeft="@+id/picButton" 
     android:layout_alignStart="@+id/imageViewL" 
     android:background="@drawable/fbfriends2" 
     android:layout_alignRight="@+id/imageViewLL" 
     android:layout_alignEnd="@+id/imageViewLL" 
     android:layout_marginBottom="20dp" /> 

    <ImageButton 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:id="@+id/sendButon" 
     android:background="@drawable/go" 
     android:layout_alignTop="@+id/toButton" 
     android:layout_alignRight="@+id/editText" 
     android:layout_alignEnd="@+id/editText" /> 

    <ImageButton 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:id="@+id/plusButtonL" 
     android:background="@drawable/plusp" 
     android:layout_alignTop="@+id/videoButton" 
     android:layout_toRightOf="@+id/imageViewLL" /> 

    <ImageButton 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:id="@+id/minusButtonR" 
     android:background="@drawable/minusp" 
     android:layout_alignTop="@+id/videoButton" 
     android:layout_toLeftOf="@+id/imageViewRR" /> 

    <ImageButton 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:id="@+id/plusButton" 
     android:background="@drawable/plusp" 
     android:layout_alignTop="@+id/videoButton" 
     android:layout_centerHorizontal="true" /> 

    <ImageButton 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:id="@+id/minusButton" 
     android:background="@drawable/minusp" 
     android:layout_alignTop="@+id/videoButton" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="300dp" /> 

</RelativeLayout> 

Ich füge die GridView programmatisch:

gv=new GridView(ma); 
      List<Student> hhh=new ArrayList<Student>(); 
      if (FriendPickerApplication.selectedUsers!=null) { 
       if (FriendPickerApplication.selectedUsers.size() > 0) { 
        for (GraphUser gu : FriendPickerApplication.selectedUsers) { 
         hhh.add(new Student("name", gu.getId())); 
        } 
       } 
      } 

      StudentAdapter sta=new StudentAdapter(ma,hhh); 

      //gv=(GridView)pView.findViewById(R.id.gridView2); 
      gv.setVisibility(View.VISIBLE); 
      MainActivity.wantedPicSize=ma.screenWidth/12; //6 
      int wantedSize=MainActivity.wantedPicSize+2; //10 

      RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(
        RelativeLayout.LayoutParams.MATCH_PARENT, 
        RelativeLayout.LayoutParams.MATCH_PARENT); 
      relativeParams.addRule(RelativeLayout.LEFT_OF, btnSend.getId()); 
      relativeParams.addRule(RelativeLayout.RIGHT_OF,picFriends.getId()); 
      relativeParams.addRule(RelativeLayout.ALIGN_TOP, picFriends.getId()); 
      relativeParams.addRule(RelativeLayout.ALIGN_BOTTOM, picFriends.getId()); 
      gv.setLayoutParams(relativeParams); 
      gv.setPadding(5,0,5,0); 
      ((RelativeLayout)pView.findViewById(R.id.rID)).addView(gv); 

      ViewGroup.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
        RelativeLayout.LayoutParams.FILL_PARENT, 
        RelativeLayout.LayoutParams.FILL_PARENT);//gv.getLayoutParams(); 

      relativeParams.height = wantedSize+(int)(wantedSize/5); //this is in pixels 
      relativeParams.width = (int)(ma.screenWidth/3.0);//gv.getLayoutParams().width; //(int)((((ma.screenWidth*3)/4)/wantedSize)*wantedSize); 

      gv.setColumnWidth(wantedSize); //+width betwen profiles 
      gv.setVerticalSpacing(5); 
      //gv.setNumColumns((int)((screenWidth/2)/100)); 
      gv.setNumColumns((relativeParams.width/wantedSize)); 
      System.out.print("COLUMNSSSSSSSSSS- "+(relativeParams.width/wantedSize)); 
      gv.setLayoutParams(relativeParams); 
      gv.setVisibility(View.VISIBLE); 

      gv.setAdapter(sta); 
+0

könnten Sie bitte einige Screenshots posten? Ich habe Schwierigkeiten, sich vorzustellen, wie das Problem aussieht, wenn möglich post eins, wo dein 'popupwindow' funktioniert (auf einigen Geräten wie du sagst) und eins, wo es nicht – TomTsagk

+0

Ich habe die guten und schlechten Screenshots hinzugefügt. – user2162550

+0

Könnten Sie bitte Ihr Layout angeben ?. Auch könnte es besser sein, Dialog/DialogFragment zu verwenden –

Antwort

0

Ich stimme der Antwort von Pasquale Anatriello zugestimmt. Obwohl u kann können Sie verschiedene Methoden versuchen:

mPopUpWindow.showAsDropDown(anchor); 
mPopUpWindow.showAsDropDown(anchor, xoff, yoff); 
mPopUpWindow.showAtLocation(parent, gravity, x, y); 

Ich schlage vor, Sie sollten popUp erst nach Aktionsleiste ziehen lassen, nehmen Sie y-Achse versetzt und die Schwerkraft oben, sagen: yOffset entspricht ActionBar Höhe, wenn Sie Maßnahmen haben bar ~ Höhe x 10% der Gerätehöhe, [layout_weight = 1.0]. Auch wenn es nicht funktionierte erstellen Sie eine benutzerdefinierte Ansicht [sagen Lineares Layout], die erscheint und verschwindet und fungiert als Popup-Fenster und geben Sie Flexibilität wie Sie wollen, behandeln Klicks selbst, machen es wie ein Toggle, siehe Code für Animation ::

Animation fadeInAnimation = AnimationUtils.loadAnimation(v.getContext(), android.R.anim.fade_in); 
     fadeInAnimation.setDuration(10); 
     v.startAnimation(fadeInAnimation); 

    Animation fadeOutAnimation = AnimationUtils.loadAnimation(v.getContext(), android.R.anim.fade_out); 
     fadeOutAnimation.setDuration(10); 
     v.startAnimation(fadeOutAnimation); 
1

Ihr Problem hier ist das Popup-Fenster. Es gibt keine Möglichkeit, die Aktionsbalken unter die Aktionsleiste zu verschieben, da die Aktionsleiste in einem anderen Fenster angezeigt wird, das sich unterhalb des neuen Fensters befindet, das Sie erstellen. Darüber hinaus wird die Verwendung eines Popup-Fensters für dieses komplexe Layout niemals effizient sein. Haben Sie daran gedacht, Ihre Map und das Layout, das Sie in das Popup-Fenster einfügen, in ein benutzerdefiniertes Layout zu verpacken? Das wäre wahrscheinlich die einfachere Lösung

+0

'mit einem Popup-Fenster für das komplexe Layout wird nie effizient funktionieren '- warum? – user2162550

Verwandte Themen