2016-02-26 60 views
-1
<?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="match_parent" 
       android:padding="2dp" 
       android:background="@drawable/cell_background"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:textSize="15dp" 
     android:text="New Text" 
     android:gravity="center" 
     android:background="@color/white" 
     android:id="@+id/textView"/> 

</LinearLayout> 

我碰到一个问题就来了,TextView没有显示完整的文本,我绝对不能限制码文本长度(而不是其他任何东西!)。的Android TextView中不显示完整的长文

当我使用setText与以下字符串:

qwertyuyiopasdfghjklkjsdfhvrtcgwrgcrcrfcwerm,fixcumreiovtreuiocfmruefcmeroiwurewmiohgxiehgiocwrhhhhwemoggruiohwgcioweruhcmrehxrmeihouxe,horhxihuxchfjkhjklsdfhdlkfhdsjflkasdhjfhaskldfhdkljfhsadjfkhdsjfdsakflajdasghsdlkacvnsadohlkfjhdjkflsadhkjfhasdlkfhdsjlkfhdjlkfhasdjfhicnerjsdklfhdjsklfhdsjklfhasdjklvcnsldkjfldksfhajsldkfhdjklsjfhasdjklf789456123

那只能说明:

qwertyuyiopasdfghjklkjsdfhvrtcgwrgcrcrfcwerm,fixcumreiovtreuiocfmruefcmeroiwurewmiohgxiehgiocwrhhhhwemoggruiohwgcioweruhc

enter image description here

getText返回完整的字符串的Hierarchy Viewer截图如图所示!

enter image description here

+0

其实我重新设置代码中的布局参数使得有足够的空间来设置文本。但问题是TextView获得了空间来显示文本,但它只是不显示完整的文本.------ plz参考图像 –

回答

0

您的文字过长尝试把文本视图中滚动

<?xml version="1.0" encoding="utf-8"?> 
 
<android.support.v4.widget.NestedScrollView 
 
    xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
 
    xmlns:tools="http://schemas.android.com/tools" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    android:layout_marginTop="40dp" 
 
    android:layout_marginBottom="40dp" 
 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
 
    tools:context="com.bala.computer.thenaliramanstories.ScrollingActivity"> 
 

 

 
    <WebView 
 
     android:id="@+id/txtStory" 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:layout_margin="@dimen/text_margin"/> 
 

 
</android.support.v4.widget.NestedScrollView>

+0

任何其他解决方案?我想找出为什么不能显示全文!据我所知,TextView可以显示比这更多的文本。 –

+0

谢谢,但我发现一些代码在深角落:textView.setMaxLines(6); -----我的错! –

-1

更改的LinearLayout的android:layout_width="match_parent"

+0

对不起,我添加了一个图像,Plz看看图像[1]。我不认为这是问题 –

+0

其实我重新设置代码中的布局参数,以便有足够的空间来设置文本。但问题是TextView只能显示文本的空间,但它不显示完整的文本。 –

-1

你父视图具有100dp的宽度。

android:layout_width="100dp" 
       android:layout_height="50dp" 

改变他们match_parent,它应该是罚款

+0

对不起,我添加一个图片,Plz看看图片[1]。我不认为这是问题 –