簡體   English   中英

當文本超過TextView大小時,如何讓TextView自動垂直滾動?

[英]How to let a TextView scroll automatically vertically when the text exceeds the TextView size?

我正在嘗試在播放視頻時自動垂直滾動文本視圖。 我的文字太長,無法容納在屏幕上,我想在活動開始時自動滾動它。 我遵循了此處發布的有關堆棧溢出的所有教程或技巧,但我不知道。

這是我的課程文件:

public class TextSrcollActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_text_srcoll);

    TextView tv=(TextView)findViewById(R.id.textView1);
    tv.setMovementMethod(new ScrollingMovementMethod());
    tv.setSelected(true);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.text_srcoll, menu);
    return true;
}
}

這是我的XML文件:

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginRight="3dp"
android:layout_marginTop="3dp"
android:background="#ff737373"
android:gravity="center"
android:minWidth="64dp"
android:orientation="vertical"
android:padding="3dp" >
<TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:marqueeRepeatLimit="marquee_forever"
    android:maxWidth="100px"
    android:scrollHorizontally="false"
    android:scrollbars="vertical"
    android:gravity="bottom"
    android:singleLine="false"
    android:textColor="#ffd9d9d9"
    android:textSize="16sp"/>
</LinearLayout>

在XML文件中,我嘗試更改某些屬性,但仍然一無所有。

在滾動視圖內使用textview。

<ScrollView   
android:id="@+id/ScrollView01"  
android:layout_height="fill_parent"   
android:layout_width="fill_parent">

<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:maxWidth="100px"
android:scrollHorizontally="false"
android:scrollbars="vertical"
android:gravity="bottom"
android:singleLine="false"
android:textColor="#ffd9d9d9"
android:textSize="16sp"/>

</ScrollView>

多行文本視圖上的ellipsize存在問題。 這是一個舊的問題報告,位於此處: http : //code.google.com/p/android/issues/detail?id=2254

錯誤報告的底部有一個解決方法,SO上還有另一個解決方法: android ellipsize多行textview

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM