android布局添加布局,Android-向布局添加视图,使布局位于ActionBar前面

我有一个视图,我正在创建一个PopupWindow 。 在这个PopupWindow ,我有一个文本框( EditText )。 单击以编辑文本时,键盘将打开,整个视图会上升,但视图顶部会平滑地位于操作栏视图下方 。 到现在为止还挺好。

我现在已经添加了一个没有任何进一步配置的空GridView到PopupWindow ,现在同样的情况发生但视图的整个顶部位于操作栏视图的顶部并且不平滑(当键盘消失时,popup窗口变得一团糟popup窗口位置会在几秒钟内发生变化,键盘上会有“剩余时间”,持续一秒钟。 它也发生在ListView 。

我希望视图的顶部可以顺利地进入’ActionBar`。

有任何想法吗?

更新:通过以编程方式添加GridView我在一些设备上部分地解决了它,但在某些设备上它仍然会发生。

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

好:

SsI7W.png

坏:

RSyk5.png

布局:

我正在以编程方式添加GridView :

gv=new GridView(ma); List hhh=new ArrayList(); 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);

我同意Pasquale Anatriello发布的答案。 虽然你可以尝试不同的方法:

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

我建议你应该让popUp只在Action Bar之后绘制,取y轴偏移和重力顶部,说:yOffset等于动作栏高度,如果你有动作栏〜高度x设备高度的10%,[layout_weight = 1.0]。 即使它没有成功创建一个自定义视图[说线性布局]出现并消失,像popup窗口一样,给你你想要的灵活性,自己处理点击,使它像切换,看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);

这里的问题是popup窗口。 由于操作栏显示在您正在创建的新窗口下方的另一个窗口中,因此无法将其移至操作栏下。 而且,使用popup窗口进行复杂的布局永远不会有效地执行。 您是否考虑过在自定义布局中将地图和布局放在popup窗口中? 这可能是更容易的解决方案

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值