2017-10-30 11 views
-4

私はトーストテキストをランダムに電話画面に表示するコードをテストしています。 Toast Gravityのxとyオフセットの最大値はどれくらいですか?Toast.setGravityのx、yオフセットの範囲はどれくらいですか?

int i=0; 
while(i < 100){ 
    Random rand = new Random(); 
    int xOffset = rand.nextInt(500); //what is the max number for this? 
    int yOffset = rand.nextInt(700); //what is the max number for this? 
    Context context = getApplicationContext(); 
    CharSequence text = "Hello toast!"; 
    int duration = Toast.LENGTH_SHORT; 
    Toast toast = Toast.makeText(context, text, duration); 
    toast.setGravity(Gravity.TOP|Gravity.LEFT,xOffset,yOffset); 
    toast.show(); 
    i++; 
} 

答えて

0

official docはこれを具体的に教えていません。私は、Gravity.CENTER_VERTICALはトーストを画面中央に置くと仮定します。 xとyのオフセットはピクセル単位であるため、最大値は表示幅/高さです。

関連する問題