這個問題已經被問到了多少次,但是我沒有從我那裏得到任何答案。調整TextView的大小以使用XML來包裝內容
如何獲取textview以調整自身大小以適應大於單行的文本(可能爲5行左右)?請注意,我正在尋找解決方案來處理XML ONLY。
<TextView
android:id="@+id/item_comments_textview_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/comments_comment"
android:textAppearance="?android:attr/textAppearanceSmall" />
這裏是我嘗試沒有任何影響的屬性。
android:singleLine="false"
android:maxLines="5"
android:scrollHorizontally="false"
android:layout_height="0dip"
android:layout_weight="1"
android:inputType="textMultiLine"
有人可以讓我知道如何使textview的大小增加,沒有指定一個恆定的高度?
我總XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="horizontal"
android:paddingBottom="24dp"
android:paddingTop="20dp" >
<ImageView
android:id="@+id/item_comments_imageview"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:contentDescription="@string/empty"
android:scaleType="fitXY"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="16dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/item_comments_author"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_weight="0.50"
android:ellipsize="end"
android:maxLines="1"
android:gravity="top"
android:text="@string/comments_author"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<TextView
android:id="@+id/item_comments_comment_date"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:gravity="right"
android:text="@string/comments_date"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<TextView
android:id="@+id/item_comments_textview_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/comments_comment"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
我想ID爲「item_comments_textview_comment」增長,以適應用戶給出的評論,以高達最多5行的TextView。目前它只顯示1行並剪切剩下的文本。
它的工作原理..很多 –