TextView不会垂直滚动,除非其中有链接

时间:2012-04-16 03:35:09

标签: android android-layout

我已经在我的TextView中启用了ScrollView中的垂直滚动(为了在水平滚动时将其他内容留在顶部) - 但垂直滚动仅在有链接时才有效TextView的数据。如果没有网址/电子邮件/等,则垂直滚动不起作用。

当它工作时,垂直滚动条也会报告错误的滚动位置 - 在视图中滚动100%,它将最多移动到屏幕的5%。

这里有问题的xml布局会产生这种奇怪的行为,而 newsreader_message 是我希望能够正确滚动的那个:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/newsreader_subjectdate"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:marqueeRepeatLimit="1"
    android:scrollHorizontally="true"
    android:text=""
    android:textAppearance="?android:attr/textAppearanceSmall" />

<TextView
    android:id="@+id/newsreader_fromto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:marqueeRepeatLimit="1"
    android:scrollHorizontally="true"
    android:text=""
    android:textAppearance="?android:attr/textAppearanceSmall" />

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/newsreader_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:autoLink="web|email"
        android:contentDescription="News post content"
        android:keepScreenOn="true"
        android:paddingRight="10dp"
        android:paddingTop="6dp"
        android:scrollHorizontally="true"
        android:scrollbars="horizontal|vertical"
        android:text=""
        android:textSize="11.5sp"
        android:typeface="monospace" />
</ScrollView>

作为一个额外的细节,当垂直滚动被打破(并且马戏团需要滚动)时,马戏团不会滚动。

2 个答案:

答案 0 :(得分:0)

将textview的layout_width更改为“fill_parent”并尝试一次

答案 1 :(得分:0)

ScrollViews布局应该是wrap_content。另一个选项是让scrollview做滚动,textview填充空格如下

<ScrollView     android:id="@+id/scrollView1"    
 android:layout_width="wrap_content"    
 android:layout_height="wrap_content" 
android:scrollHorizontally="true"         
android:scrollbars="horizontal|vertical" 
android:fillViewport="true" >      
    <TextView         
android:id="@+id/newsreader_message"         
android:layout_width=""fill_parent"        
 android:layout_height="fill_parent"         
android:autoLink="web|email"         
android:contentDesciption="News post content"        
 android:keepScreenOn="true"         
android:paddingRight="10dp"         
android:paddingTop="6dp"                
  android:text=""        
 android:textSize="11.5sp"        
 android:typeface="monospace"  
android:layout_weight="1.0" /> 
</ScrollView> 
相关问题