我对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在文本足够长时切断文本。有什么不对,有人知道吗?
利用这些属性
android:lines="1"
android:scrollHorizontally="true"
android:ellipsize="end"
最后会追加“......”。但这不会解决蜂窝标签中的问题
因此对于蜂窝平板电脑也添加以下属性
android:singleLine="true"
另一方面,如果你需要选框效果
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true
是的,您需要设置一些属性,但首先让我们知道您想要什么类型的textview,单行还是多行?
您可以使用以下属性:
android:singleLine="true" // or false
android:ellipsize="marquee" // must check
android:lines="1"
你需要设置android:minLines =“2”
如果您希望视图的文本长度不同,或者您要更改textSize
的不同实例的TextView
,那么您应该使用View.addOnLayoutChangeListener()
。
在布局文件中设置下面的属性。这对我来说可以
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusableInTouchMode="true"