2012-11-05 54 views
0

我有一个似乎很奇怪的问题。这是代码;android to long text for scrolable view

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/bghome" > 

    <TableRow> 

     <TextView 
      android:id="@+id/TextTitle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="10dp" 
      android:layout_marginTop="10dp" 
      android:gravity="center" 
      android:text="Wrocław" 
      android:textColor="#FFFFFF" 
      android:textSize="20dp" /> 
    </TableRow> 

    <TableRow> 

     <ScrollView 
      android:layout_width="fill_parent" 
      android:layout_height="400dp" 
      android:layout_marginLeft="10dp" > 

      <TextView 
       android:id="@+id/TextMain" 
       android:layout_width="300dp" 
       android:layout_height="400dp" 
       android:layout_gravity="center_vertical|right" 
       android:text="Ładowanie danych..." > 
      </TextView> 
     </ScrollView> 
    </TableRow> 

</TableLayout> 

现在。当我把很长的文本放在TextView中(在Scrolable视图中)。我遇到了流产问题。文本顶部被削减。 (目标是创建一个标题,并在其下方为serwer的html文本的可缩小容器 - 一个html代码)。

身份证无关紧要的是我把html字符串放在纯字符串上,或者我从serwer或硬编码中获取数据。我尝试了所有的组合,我无法破解它。

MainText.setText(Html.fromHtml(Plain_str)); 
MainText.setText(Plain_str); 
MainText.setText(Plain_str.toString()); 

没有什么帮助。

+0

只是出于兴趣,这是你的整个XML文件? – cjk

+0

如果你为'ScrollView'和'TextView'设置'TableRow'高度为400dp,然后'match_parent',会发生什么情况。我有这个布局高度的问题,直到我做了这个改变,然后它似乎*一切工作正常。 – jnthnjns

+0

嗨,你好,谢谢你的回复。我发现了这个问题。它在这一行:android:layout_gravity =“center_vertical | right”。 (我不明白为什么)。解释欢迎:) –

回答

1

问题是在这一行:机器人:layout_gravity = “center_vertical |右”

0

我可能误解的问题,但你有没有尝试设置TableRow高度400dp,然后为ScrollViewTextViewmatch_parent?我有这个布局高度的问题,直到我做了这个改变,然后它似乎一切正常。

事情是这样的:

<TableRow 
    android:layout_width="match_parent" 
    android:layout_height="400dp" > 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginLeft="10dp" > 

     <TextView 
      android:id="@+id/TextMain" 
      android:layout_width="300dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="center_vertical|right" 
      android:text="this is very long text that is going in a textview wrapped by a scrollview. I want to see how the text is displayed when wrapped. this is very long text that is going in a textview wrapped by a scrollview. I want to see how the text is displayed when wrapped." > 
     </TextView> 
    </ScrollView> 

</TableRow> 
+1

Thx。但我的意思是像这样的一百倍的文本:)。无论如何,重力是问题所在。 –

+0

好,但我不确定为什么会产生问题。你想让'TextView'成为'center_vertical |正确“或视图内的文字?由于这是唯一的孩子,它适合父母分配给'TextView'似乎是多余的,除非我缺少一些东西,如果你想将它们分配给文本,请尝试用'android:gravity =“center_vertical | right”替换它在视图内。 – jnthnjns

+0

我正在尝试在android中创建文本对齐。 –