TextView отключает текст, если он достаточно длинный
У меня странная проблема с TextView, она отсекает часть текста в конце. Мой макет выглядит как
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top|center_horizontal"
android:gravity="top|center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top|center_horizontal"
android:gravity="top|center_horizontal"
android:orientation="horizontal"
android:layout_weight="1"
android:layout_marginBottom="5dp">
<Button
android:id="@+id/btnPreviousQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selector_arrow_left"
android:clickable="true"
android:visibility="gone" >
</Button>
<TextView
android:id="@+id/txtQuestion"
style="@style/question_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top|center_horizontal"
android:layout_weight="1"
/>
<Button
android:id="@+id/btnNextQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:background="@drawable/selector_arrow_right"
android:clickable="true" >
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:orientation="horizontal" >
<WebView
android:id="@+id/wvMultimediaQuestion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginLeft="50dp"
android:layout_marginRight="55dp"
android:layout_weight="1"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
и txtQuestion отключает текст, когда он достаточно длинный. Что не так, знает кто-нибудь?
Ответы
Ответ 1
Использовать эти атрибуты
android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"
добавит "..." в конце. Но это не решит проблему на вкладке сотовой связи.
Итак, для планшета сотовой связи добавьте следующий atttibute
android:singleLine="true"
С другой стороны, если вам нужен эффект выделения
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true
Ответ 2
Да, есть некоторые атрибуты, которые вам нужно установить, но сначала сообщите нам, какой тип текстового представления вы хотите точно, одну строку или несколько строк?
Есть некоторые атрибуты, о которых вы можете позаботиться:
android:singleLine="true" // or false
android:ellipsize="marquee" // must check
android:lines="1"
Ответ 3
Вам нужно установить андроид: minLines = "2"
Ответ 4
Если вы ожидаете различную длину текста для своего представления или вы собираетесь изменить textSize
разных экземпляров вашего TextView
, тогда вы должны использовать View.addOnLayoutChangeListener()
.
См. пример здесь: fooobar.com/info/62161/...