当按下它时,我需要在操作栏中的按钮(菜单)下方显示弹出窗口。除 Nexus 7 和三星 Galaxy S4 外,所有设备都运行良好。令人惊奇的问题是弹出窗口没有填满整个屏幕。我在上面提到的高分辨率设备中发现了这个问题。在这里,我附上了清晰显示问题的屏幕截图。
结果,我面临从左侧测量箭头位置的问题,当用户按下菜单时,我需要计算以动态移动箭头。在这里,我在操作栏上单击的菜单下方显示箭头时遇到了麻烦。
问题
1)尽管布局婴儿车与父级匹配,但设备屏幕上未填充弹出窗口 2)箭头向右移动,移动距离等于屏幕最左侧的间隙。
我做了什么
更多是操作栏上的单击视图(菜单)
more.getLocationOnScreen(xy);
int[] parentxy = new int[2];
((LinearLayout) aerrowHead.getParent()).getLocationOnScreen(parentxy);
final Rect rect = new Rect();
rect.left = xy[0];
Log.v("More", "Left :" + xy[0] + "bottom" + xy[1]);
Log.v("arrow head parent", "Left :" + parentxy[0] + "bottom"
+ parentxy[1]);
rect.top = xy[1] - more.getWidth() / 2;
rect.right = xy[0] + more.getWidth();
rect.bottom = xy[1] + more.getHeight() / 2;
popup.showAsDropDown(more);
android.widget.LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
int marginLeft = xy[0] - parentxy[0] + more.getWidth() / 2
- aerrowHead.getWidth() / 2;
layoutParams.setMargins(marginLeft, 0, 0, 0);
aerrowHead.setLayoutParams(layoutParams);
popup.setFocusable(true);
布局是
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:layout_marginTop="8dp"
android:background="@color/notification_panel_bgcolor"
android:orientation="vertical" >
<TextView
android:id="@+id/txtNotificationTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:padding="10dp"
android:text="Notification"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#4A546C" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical" >
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="@null"
android:divider="#C7C7C8"
android:dividerHeight="1dp"
android:listSelector="@null"
android:visibility="gone" >
</ListView>
<LinearLayout
android:id="@+id/errorLoadingLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="horizontal"
android:visibility="visible" >
<ImageView
android:id="@+id/errorLoadingImage"
android:layout_width="50dp"
android:layout_height="50dp"
android:scaleType="centerCrop"
android:src="@drawable/ic_friendrequest"
android:visibility="gone" />
<ProgressBar
android:id="@+id/load_more_progressbar"
style="?android:attr/android:progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/txtErrorLoading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="@android:color/transparent"
android:gravity="center"
android:shadowColor="#ffffff"
android:shadowDy="2"
android:shadowRadius="0.3"
android:text="Error In Loading"
android:textColor="#576586"
android:textSize="14sp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top" >
<ImageView
android:id="@+id/aerrowHead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_notification_popup_arrowhead" />
</LinearLayout>