1

TextView のカスタム trur タイプ フォントを設定し、テキスト サイズを設定しています。次に setText() メソッドを使用して、テキストを TextView に設定します。完璧なテキストを表示します。しかし、この TextView のベースラインを取得しようとすると、1 または -1 と表示されます。それはなぜです??

私はこのようにしています。

TextView tv;
tv.setTypeface(Typeface.createFromAsset(getAssets(),"customFont.ttf"));
tv.setTextSize(20);
tv.setText("My name is Tahir");

tv.getBaseline(); 
//this returns -1. (if i set Height and width of tv suppose 100 the getBaseline() retruns 1)
tv.getTop();
tv.getBottom();

何が問題なのか教えてください???

4

2 に答える 2

0

レイアウトとレンダリングが既に行われた後でベースラインを取得してみてください。たとえば、それは間違いなく onCreate(...) の後です。

于 2012-11-29T14:01:00.983 に答える
0

android:baselineAlignedXMLで使用したものは何でも、線形または相対レイアウトで宣言しましたか。

例えば ​​:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:baselineAligned="true" >

    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/hello"
        android:id="@+id/text1" />

</LinearLayout>
于 2012-02-24T09:41:16.183 に答える