私はシンプルなタイルでアイソメトリックマップを作成しています。これらのタイルを保持するレイアウトを作成するには、をRelativeLayout
に拡張しました。実際には、ちょうどRelativeLayout
をそのまま使っても、私の向きがXMLファイルに書き込まれた順番と一致していれば問題ありません。すべて’が上書きされたコンストラクタは、super
とsetChildrenDrawingOrderEnabled(true);
を呼び出し、いくつかの変数(グリッドの高さと幅)を設定してからgetChildDrawingOrder
と呼ぶだけです。getChildDrawingOrderが不当に呼び出されましたか?
与えられた子供のための新たな指標うちgetChildDrawingOrder
数値のための私のコードでは、ともi
は、元の索引とi'
が新しいインデックスであるi->i'
の子で文字列を設定します。私は’ mこれをテストに使用します。子どもたちは座標と一緒にこの文字列を描画するように設定されています。
残念ながら、正しく動作しないか、むしろ不安定に動作します。私のテストケースの9つのタイルのうち、’の3つのドンは、まったくgetChildDrawingOrder
というように見えます。上記の文字列は、null
です。残りのうち、正しいインデックスが渡されたにもかかわらず、少なくとも1つは順序が乱れています。ここ
’ SA(TOP
向きの)画像(0,2)、(1,2)、および(2,1)は全てNULL
として表示されていること
お知らせそのためにgetChildDrawingOrder
が呼び出されたことはありません。また、i
(3)とi'
(1)の両方が(1,1)’(4と4)未満であっても、(1,1)の上に(1,0)が描画されていることにも注意してください。
ここ’のgetChildDrawingOrder
からコード:
@Override
protected int getChildDrawingOrder(int childCount, int i)
{
TileView ch = (TileView)getChildAt(i);
ch.order = "Called"; // this string is drawn on my children
int gx, gy; // the "true" x,y for the current rotation,
// where 0,0 is the top corner
switch (rotation)
{
case TOP:
gx = ch.x();
gy = ch.y();
break;
case LEFT:
gx = (width()-1-ch.x());
gy = ch.y();
break;
case RIGHT:
gx = ch.x();
gy = (length()-1-ch.y());
break;
case BOTTOM:
gx = (width()-1-ch.x());
gy = (length()-1-ch.y());
break;
default:
gx = ch.x();
gy = ch.y();
}
int row = gx+gy; // current row
if (row == 0) // row 0 is always just the top corner and 0
{
ch.order = new String(i+"->0"); // string set to i->i'
return 0;
}
else
{
int mx = width()-1, // maximum x value
my = length()-1, // maximum y value
mrow = mx+my, // maximum row
min = Math.min(mx, my), // minor axis length
maj = Math.max(mx, my), // major axis length
retn; // for storing the return value
// inside the top corner
if (row <= min)
{
// Gauss's formula to get number of cells in previous rows
// plus the number for which cell in this row this is.
retn = row*(row+1)/2+gy;
}
// in the middle
else if (row <= maj)
{
// Gauss's formula to get number of cells in top corner
// plus the number of cells in previous rows of the middle section
// plus the number for which cell in this row this is.
retn = min*(min+1)/2+min*(row-min)+gy;
}
// bottom corner
else
{
retn = (min+1)*(min+2)/2 // cells in the top corner
+ min*(maj-min) // cells in the middle
+ (mrow-maj)*(mrow-maj+1)/2 // total cells in bottom triangle
- (mrow-row+1)*(mrow-row+2)/2 // less cells after this one
+ gy // which cell in this row
- (row-maj) // to account for gy not starting at zero
;
}
ch.order = new String(i+"->"+retn); // string set to i->i'
return retn;
}
}
誰もが’ sが起こって何にいくつかの光を当てることができますか?なぜこれらの3つのタイルにisn ’ t getChildDrawingOrder
が呼び出されていますか? getChildDrawingOrder
がであるにもかかわらず、(1,0)が間違った順序で描かれているのはなぜですか?
これはもう少し紹介が必要なような気がします。私は何年もAndroidの開発から離れていましたので、このコードを読み、それが何をしているのかを理解するために少し掘り下げなければなりません。それをしなければ、私はこれが良い答えであるかどうかは分からない。 'getChildDrawingOrder'とそれがどのように動作するか/それがどのように使用されているかについてのより多くの説明はそれを助けるでしょう、と私は思います。 – KRyan
説明のためにいくつかの画像を追加します – petey