2011-06-27 4 views
0

これはコードです。基準点は親の高さです。テキストは、親の高さに達するまで増加する必要があります。しかし、この要素は可視領域を超えて成長し続けます。母親の高さで見るストップが増えますか?

1つのボタンと1つのテキストビューしかないので、XMLファイルを投稿する必要はありません。

誰もがテキストが親の身長を超えて成長し続ける理由を知っていますか?私は間違って何をしていますか?


EDIT

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.first); 

     Display display = getWindowManager().getDefaultDisplay(); 
     final int screenWidth = display.getWidth(); 
     final int screenHeight = display.getHeight(); 

     textView = (TextView) findViewById(R.id.textview); 

     button = (Button) findViewById(R.id.button); 
     button.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 
       int dTextWidth = textView.getWidth(); 

       if (dTextWidth <= screenHeight) { 
        textView.setTextSize(textView.getTextSize() + 1); 
       } 
      } 
     }); 
    } 

おかげで私はLinearLayoutの高さを使用し、それはまだ動作しません。さらに、LinearLayoutの高さは0 !!!!!

LinearLayout lin = (LinearLayout) findViewById(R.id.linear_layout); 
final int layoutHeight = lin.getHeight(); 
Toast.makeText(this,"LinLay height: "+layoutHeight,Toast.LENGTH_SHORT).show(); 
... 
     button = (Button) findViewById(R.id.button); 
     button.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View view) { 
       int displayTextWidth = textView.getWidth(); 

       if (displayTextWidth <= layoutHeight) { 
        textView.setTextSize(textView.getTextSize() + 1); 
       } 
      } 
     }); 
+0

hierarchyviewer – pawelzieba

+0

どうすればよいですか?私は何を探すべきですか?どの要素によってこれが機能しなくなっていますか? – sandalone

答えて

0

テキストの幅と画面の高さを比較しています。それは簡単な間違いです。 これに変更してください。

if (dTextWidth <= screenWidth) { 
    textView.setTextSize(textView.getTextSize() + 1); 
} 
+0

はい、それは幅に成長します。私はそこで止めたくありません。私はそれがテキストのビューは、行を自動的に壊すことができるので、親の高さまで成長したい。テキストには1単語以上ありますので、3つの大きな単語を画面に表示します。 – sandalone

+1

'Display'オブジェクト、[Display.getHeight()](http://developer.android.com/reference/android/view/Display.html#getHeight())のドキュメントを見ると、"これは一般的ではありませんデバイスは通常、ディスプレイの縁に沿って(ここで返される生のサイズから利用可能なアプリケーションスペースの量を減らす)画面デコレーション(ステータスバーなど)を持つため、レイアウトの計算に使用されます。したがって、「デバイス」高さを使用する代わりに、アプリケーションのルートビューの高さを使用します。 – venkatagiri

+0

Hm、抜群のポイント!ありがとう。それに応じて投稿を編集します。 – sandalone

関連する問題