动态的设置textview的高度

我想在应用程序中给textview动态的设置文本,所以我想实现textview能动态调整大小。我按照以下代码设置,但是没设置成功:

<TextView
android:id="@+id/TextView02" 
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="normal"
android:text="Frontview"
android:layout_weight="1"
android:gravity="center_vertical"
android:textColor="#0099CC"
android:singleLine="false"
android:maxLines="4"
android:ellipsize="marquee"
/>

Textview的高度不会超过2行,里面的文本也不能消减。

像znl_12说的,除非你删除android:maxLines="4",否则超过4行,上面的代码就可以忽略了。
要这样设置高度:

TextView tv = (TextView) findViewById(R.id.TextView02);
int height_in_pixels = tv.getLineCount() * tv.getLineHeight(); //approx height text
tv.setHeight(height_in_pixels);

可以通过像素的方法设置大小:

getResources().getDisplayMetrics().density;

也可以用滚动条的方式调节text的大小:

TextView tv = (TextView)findViewById(R.id.TextView02);
tv.setMovementMethod(ScrollingMovementMethod.getInstance());

删除android:maxLines = " 4 ",它限制了视图的的4行文本的高度。