2013-07-20 3 views
1

정확한 위치 대신 버튼 아래에 팝업을 표시하려면 어떻게합니까? 현재이 팝업이 표시되는 위치를 설정 내 코드,버튼 아래에 팝업을 표시하는 방법 - 안드로이드

popUpFollowUsername.showAtLocation(findViewById(R.id.dashboardRelative), Gravity.TOP, 100, 280); 

는 내가이 버튼

<Button android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/post" 
     android:paddingTop="10dip" 
     android:paddingBottom="10dip" 
     android:textSize="20sp" 
     android:textColor="#FFFFFF" 
     android:textStyle="bold" 
     android:background="@drawable/dashboard_post" 
     android:id="@+id/btnPost"/> 

내가 여러 안드로이드 폰을 가지고 팝업 다른 나타납니다에게있는 버튼 바로 아래에 표시 할 것입니다 모든 휴대 전화의 위치, 게시 버튼 바로 아래에 항상 표시되도록하려면 어떻게해야하나요?

+0

사용 @의 rekire의 대답 :

은 기본적으로 그런 일을 사용합니다. R.id.dashboardRelative의 layout_width가 match_parent로 설정된 경우이 작업이 작동합니다. 그렇지 않으면 x 값을 조정하여 팝업을 가로로 가운데에 맞출 필요가 있습니다. – Vikram

답변

0

View.getLocationOnScreen() 및/또는 View.getLocationInWindow()을 사용하면 화면에서보기 위치를 얻을 수 있습니다. 이 정보를 사용하면 팝업을 버튼 근처에 놓기가 쉽습니다. ;`(하지 테스트)`popUpFollowUsername.showAtLocation (findViewById를 (R.id.dashboardRelative), Gravity.TOP, 0, y)를 같은

Button btn = get(); // maybe with findViewById 
btn.setOnClickListener(new OnClickListener() { 
    void onClick(View v) { 
     int[] pos = new int[2]; 
     v.getLocationInWindow(pos); 
     int x = pos[0]; 
     int y = pos[1] + v.getHeight(); 
     // show popup at the given x,y position 
    } 
}); 
+0

이것이 나를 혼란스럽게합니까 ?? –

+0

나는 아래쪽에 팝업이 나타나기를 원하지 않는다. 나는 포스트 버튼 아래에 그것을 원한다. –

+0

y 세로줄에 단추의 높이를 더하면 원하는 것을 가질 수있다. – rekire

관련 문제