簡體   English   中英

如何設置textview的大小取決於文本中的長度?

[英]How to set the size of textview depends on the length of text in the?

我正面臨這樣的情況:

我的左側和右側分別有兩個textview,左邊的具有固定的內容,右邊的具有內容的長度取決於從數據庫獲取的數據的內容。

我希望兩個文本視圖具有相同的高度,因此我將兩個的高度設置為wrap_content,並在設置文本的代碼后使用getHeight()setHeight()在擴展右一個的高度時更改左一個的高度由於內容長。 結果,仍然具有不同的高度。

有人可以告訴我哪一部分是錯誤的,並提出一些方法來改變左一的高度,這取決於將右兩的高度設置為兩個textview的固定高度嗎?

 <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/bName"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/add_book_review_top_left"
                android:gravity="center"
                android:padding="5dp"
                android:text="@string/bName"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/input_bName"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:padding="5dp"
                android:background="@drawable/add_book_review_top_right"
                android:layout_weight="1" />
        </LinearLayout>
android:layout_width="wrap_content"

嘗試下面的代碼

<TextView
android:id="@+id/bName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/add_book_review_top_left"
android:gravity="center"
android:padding="5dp"
android:text="@string/bName"
android:textStyle="bold" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM