gpt4 book ai didi

Android-向布局添加 View 导致布局位于 ActionBar 前面

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:11:31 25 4
gpt4 key购买 nike

我有一个正在创建 PopupWindow 的 View 。在这个 PopupWindow 中,我有一个文本框 (EditText)。单击编辑文本时,键盘打开,整个 View 上升,但 View 顶部平滑地操作栏 View 下。到目前为止一切顺利。

我现在添加了一个空的GridView,没有对PopupWindow进行任何进一步的配置,现在发生了同样的情况,但是 View 的整个顶部都变成了在操作栏 View 的顶部 并且不平滑(弹出窗口变得一团糟,当键盘消失时,弹出窗口位置会更改几秒钟,并且键盘会出现“剩余”一秒钟)。 ListView 也会发生这种情况。

我希望 View 的顶部顺利地进入“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);

好:

enter image description here

坏的:

enter image description here

布局:

<?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>

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

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

最佳答案

这里的问题是弹出窗口。没有办法让它进入操作栏下方,因为操作栏显示在您正在创建的新窗口下方的另一个窗口中。此外,为复杂的布局使用弹出窗口永远不会有效执行。您是否考虑过将您的 map 和放置在自定义布局中的弹出窗口中的布局包装起来?这可能是更简单的解决方案

关于Android-向布局添加 View 导致布局位于 ActionBar 前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30004234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com