Android- adding view to layout causing layout to be in front of ActionBar

I have a view in which I'm creating a PopupWindow. In this PopupWindow, I have a text box (EditText). When clicking to edit the text, the keyboard opens and the whole view goes up, but the top of the view goes under the action bar view smoothly. So far so good.

I now have added an empty GridView without any further configuration to the PopupWindow, and now the same scenario happens but the whole top part of the view goes on top of the action bar view and not smooth (the popup becomes a mess, when keyboard disappears the popup location changes for couple of seconds and there are "leftovers" from the keyboard for a second). It also happens with ListView.

I want the top part of the view to go under the 'ActionBar` smoothly, as it should.

Any ideas?

UPDATE: By adding the GridView programatically I partially solved it on a couple of devices, but on some devices it's still happens.

Displaying the 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);

GOOD:

Android- adding view to layout causing layout to be in front of ActionBar

BAD:

Android- adding view to layout causing layout to be in front of ActionBar

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>

I'm adding the GridView programmatically:

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);

-------------Problems Reply------------

Your problem here is the popup window. There is no way to make it go under the actionbar since the actionbar is displayed in another window that is below the new window you are creating. moreover using a popup window for that complex layout is never going to perform efficiently. Have you thought of wrapping your map and the layout you are putting in the popup window in a custom layout? That would probably be the easier solution

I agree with the answer posted by Pasquale Anatriello. Though u can You can try different methods :

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

I suggest you should let popUp draw only after Action Bar, take y axis offset and gravity top, say: yOffset is Equivalent to actionbar height, if you have action bar ~ height x 10% of device height , [layout_weight = 1.0]. Even if it didn't work out create a custom View [say Linear Layout] that appears and disappears and acts like popup a window and give u flexibility as u want,handle clicks by yourself, make it like a toggle, see code for 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);

Category:android Views:6 Time:2018-04-06

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.099 (s). 11 q(s)