简体   繁体   English

请帮我在Android上滚动

[英]Please, help me with scrolling on android

So, here's my promblem - I have a textview, by pressing a button it will generate new text in that textview. 所以,这是我的问题-我有一个textview,通过按下按钮,它将在该textview中生成新文本。 Because the text is bigger than textview, I need to have scroll on it. 因为文本大于textview,所以我需要对其进行滚动。 Scroll works fine, you can scroll text and read it. 滚动效果很好,您可以滚动文本并阅读。 But there is a promblem - for example text1 is 30 lines long and text2 is 10 lines long. 但是有一个问题-例如text1长30行,而text2长10行。 In textview I see text1, I scroll it to the end, then I press on button and it shows text2, but because i finished watching text1 from 30th line, I will see text2 that starts from 30th line and so I see empty space and I need to manually scroll it up. 在textview中,我看到text1,将其滚动到末尾,然后按on按钮,它显示text2,但是因为我看完第30行的text1,所以我会看到从第30行开始的text2,所以我看到空白,我需要手动向上滚动。 Is there way to reset scrolling parameters after generating new text? 生成新文本后,是否可以重设滚动参数?

Please try like this. 请尝试这样。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent">

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

       <TextView 
       android:id="@+id/TEXT_VIEW" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:text="This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header" />
     </ScrollView>
    <EditText
        android:id="@+id/EDIT_TEXT"
        android:layout_height="70px"
        android:layout_width="fill_parent"
        android:layout_alignParentBottom="true"
        android:maxHeight="70px"
    />

</RelativeLayout>

[Reference] [Scrolling a TextView] 1 [参考] [滚动TextView] 1

you can also follow auto-scrolling TextView in android to bring text into view 您还可以按照android中的自动滚动TextView将文字带入视图

Best of luck! 祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM