2017-12-06 15 views
1

これは説明するのが少し複雑なので、謝罪します。Androidレイアウトの位置付け

基本的な要件は、ユーザーがデスクトップ上に描画したり、スナップショットと1つまたは2つの他のものを取ることができるAndroid上の注釈アプリです。

アプリが起動すると、1つのアイコンが表示されます。これは、デスクトップについて移動することができます。

このアイコンをクリックすると、中央のアイコンを中心に均等に広がる6つのアイコンが表示されます。

これまでのところとても良いです。ここで中央アイコンを移動し、中心アイコンの新しい位置を中心とする6つの外側アイコンの位置を再計算します。

私たちが見つけたのは、外側のアイコンが中心のアイコンに対して中心からずれていることです。中心のアイコン内のタッチの位置によって、変位はほぼ等しく見えます(ボトムXとY)。

私は何が起こるかを描こうとします。完全

まずドラッグ/移動のタッチ点が中心にある、すべてのラインアップ:

enter image description here

接触点が右にある

は、変位は左以下の通りである:

enter image description here

タッチ変位が上向きである底部である。

だから、

view.getLocationInWindow(locWXY); 
int X = locWXY[0]; 
int Y = locWXY[1]; 

の位置:

enter image description here

アイコンに「X」の位置は、それが移動したアイコンの位置からである

int shiftX = event.getX(); 
int shiftY = event.getY(); 

かららしいです衛星アイコンは次のように計算されます:

final double angle = 30.000; 
final double rad = angle * Math.PI/180.000; 
final int radius = 100; 
final int penX = (int) (X + radius * cos(rad) + shiftX); 
final int penY = (int) (Y - radius * sin(rad) + shiftY); 
final int clearX = X ; 
final int clearY = (int) (Y - radius + shiftY); 
final int closeX = (int) (X - radius * cos(rad) + shiftX); 
final int closeY = (int) (Y - radius * sin(rad) + shiftY); 
final int iFlipX = (int) (X - radius * cos(rad) + shiftX); 
final int iFlipY = (int) (Y + radius * sin(rad) + shiftY); 
final int sshotX = X + shiftX; 
final int sshotY = (int) (Y + radius + shiftY); 
final int iFolderX = (int) (X + radius * cos(rad) + shiftX); 
final int iFolderY = (int) (Y + radius * sin(rad) + shiftY); 

penLP= new RelativeLayout.LayoutParams(70, 70); 
penLP.leftMargin = penX; 
penLP.topMargin = penY; 
imbBlackPen.setLayoutParams(penLP); 

clearLP = new RelativeLayout.LayoutParams(70, 70); 
clearLP .leftMargin = clearX; 
clearLP .topMargin = clearY; 
imbClearScreen.setLayoutParams(clearLP); 

folderLP = new RelativeLayout.LayoutParams(70, 70); 
folderLP .leftMargin = iFolderX ; 
folderLP .topMargin = iFolderY; 
imbFolder.setLayoutParams(folderLP); 

sshotLP = new RelativeLayout.LayoutParams(70, 70); 
sshotLP .leftMargin = sshotX ; 
sshotLP .topMargin = sshotY; 
imbScreenCapture.setLayoutParams(sshotLP); 

iFlipLP = new RelativeLayout.LayoutParams(70, 70); 
iFlipLP .leftMargin = iFlipX ; 
iFlipLP .topMargin = iFlipY; 
imbIflipChart.setLayoutParams(iFlipLP); 

closeLP = new RelativeLayout.LayoutParams(70, 70); 
closeLP .leftMargin = closeX ; 
closeLP .topMargin = closeY; 
imbClose.setLayoutParams(closeLP); 

shiftXとshiftYをゼロにして、XとX + shiftX/2を計算する。すべて役に立たない.奇妙なことは、解像度1920 x 1200の小さな10インチタブレットではほぼ完璧に見えますが、大きな65インチタッチスクリーンでは、ズレが非常に顕著です。

何かが欠落している必要がありますが、何が分かりません。

+0

修正済み。上記のアイコン位置計算コードは、ACTION_UPとACTION_DOWNで実行する必要があります。これを大修道院として再構築し、これらの出来事の両方でそれを呼びました。 – TenG

答えて

0

上記のようにコメント...

固定。上記のアイコン位置計算コードは、ACTION_UPとACTION_DOWNで実行する必要があります。これをメソッドとしてリファクタリングし、これらの両方のイベントで呼び出しました。