protected void setQuickActionListener(View button) {
float density = mActivity.getResources().getDisplayMetrics().density;
WindowManager.LayoutParams wmlp = mActivity.getWindow().getAttributes();
button.getLocationInWindow(location);
Toast.makeText(mActivity, " l1 " + location[0] + " l2 " + location[1],Toast.LENGTH_LONG).show();
wmlp.gravity = Gravity.TOP | Gravity.LEFT;
wmlp.x = location[0]+ (int) (((button.getWidth()/2) + button.getHeight()/4)/density);
wmlp.y = location[1] + (int) ((button.getHeight() - 60)/density);
mQuickAction.show(button, (int) wmlp.x, (int) wmlp.y);
}
여기에서 ImageButton 클릭 수신기의 x y 값을 가져 와서 빠른 동작 뷰를 표시하는 방법과이 동작 뷰의 show 메서드 코드를 표시합니다.잘못된 x 및 y 좌표 얻기 android
public void show(View anchor, int xPos, int yPos) {
preShow();
mDidAction = false;
int[] location = new int[2];
anchor.getLocationOnScreen(location);
Rect anchorRect = new Rect(location[0], location[1], location[0] + anchor.getWidth(), location[1]
+ anchor.getHeight());
mRootView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
mRootView.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
int rootHeight = mRootView.getMeasuredHeight();
int rootWidth = mRootView.getMeasuredWidth();
if (rootWidth == 0) {
rootWidth = mRootView.getMeasuredWidth();
}
int screenWidth = mWindowManager.getDefaultDisplay().getWidth();
int screenHeight = mWindowManager.getDefaultDisplay().getHeight();
arrowPos = anchorRect.centerX()-xPos;
int dytop = anchorRect.top;
int dybottom = screenHeight/4;
boolean onTop = (dytop > dybottom) ? true : false;
LinearLayout.LayoutParams rlpms;
// xPos > (screenWidth - 100
int dyleft = xPos;
int dyright = screenWidth - screenWidth/10;
boolean onRight = (dyleft > dyright) ? true : false;
if (onRight) {
if(onTop){
yPos = anchorRect.top - rootHeight/3;
im1 =(ImageView) mRootView.findViewById(R.id.arrow_down);
rlpms=new LinearLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
android.widget.LinearLayout.LayoutParams lp = (android.widget.LinearLayout.LayoutParams) im1.getLayoutParams();
lp.setMargins(0,rootHeight/3,0 ,0);
im1.setLayoutParams(lp);
Log.d("ddsaf", ""+onTop);
}
else
{
im1 =(ImageView) mRootView.findViewById(R.id.arrow_down);
rlpms=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
android.widget.LinearLayout.LayoutParams lp = (android.widget.LinearLayout.LayoutParams) im1.getLayoutParams();
lp.setMargins(0,5,0 ,0);
im1.setLayoutParams(lp);
//Log.d("ddsaf", ""+onTop);
}
xPos = anchorRect.left - rootWidth;
} else {
if(onTop){
yPos = anchorRect.top - rootHeight/3;
im1 =(ImageView) mRootView.findViewById(R.id.arrow_up);
rlpms=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
android.widget.LinearLayout.LayoutParams lp = (android.widget.LinearLayout.LayoutParams) im1.getLayoutParams();
lp.setMargins(0,rootHeight/3,0 ,0);
im1.setLayoutParams(lp);
//Log.d("ddsaf", "top "+onTop);
}
else
{
im1 =(ImageView) mRootView.findViewById(R.id.arrow_up);
rlpms=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
android.widget.LinearLayout.LayoutParams lp = (android.widget.LinearLayout.LayoutParams) im1.getLayoutParams();
lp.setMargins(0,5,0 ,0);
im1.setLayoutParams(lp);
//Log.d("ddsaf", ""+onTop);
}
xPos = xPos+rootWidth/4;
}
Log.d("ddsaf", ""+anchorRect.left);
showArrow(((onRight) ? R.id.arrow_down : R.id.arrow_up), arrowPos);
setAnimationStyle(screenWidth, anchorRect.centerX(), onRight);
mWindow.showAtLocation(anchor, Gravity.NO_GRAVITY, xPos, yPos);}
문제는 내가 한 번 infalted 레이아웃 동안 0,0 즉 잘못된 postions에서 신속한 조치 뷰를 얻고있다이 아래에 발생하는가에 infalted 된 경우 왜 어떤 아이디어 *
<LinearLayout
android:id="@+id/lyt_xx"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="60"
android:orientation="horizontal"
android:padding="@dimen/padding_small" >
<ImageView
android:id="@+id/img_separator"
android:layout_width="30dp"
android:layout_height="fill_parent"
android:layout_marginLeft="@dimen/padding_small"
android:layout_marginRight="@dimen/padding_small"
android:background="#333333" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
***<com.apps.horizontalgrid.TwoWayGridView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/xx_gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
android:padding="@dimen/padding_small"
app:cacheColorHint="#00000000"
app:gravity="fill"
app:horizontalSpacing="@dimen/padding_small"
app:numColumns="auto_fit"
app:numRows="2"
app:rowHeight="260dp"
app:scrollDirectionLandscape="horizontal"
app:scrollDirectionPortrait="horizontal"
app:verticalSpacing="@dimen/padding_small" >
</com.apps.horizontalgrid.TwoWayGridView>***
</LinearLayout>
<!-- -->
</LinearLayout>
<!-- -->
실제로 달성하고 싶은 것은 무엇입니까? – pskink
try.getLocationOnScreen() – techieWings
코드의 첫 번째와 두 번째 부분에서 사용했습니다. (anchor.getLocationOnScreen (location);) –