2013-12-22 48 views
0

我正在開發一個秒錶應用程序。我想滾動一個TextView

我要滾動只一個TextView。

這裏的XML文件。

activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#001729" 
android:orientation="vertical" > 



<Button 
    android:id="@+id/btn_rec" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:enabled="false" 
    android:onClick="myOnClick" 
    android:text="Record" /> 

<Button 
    android:id="@+id/btn_start" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/btn_rec" 
    android:layout_alignParentLeft="true" 
    android:onClick="myOnClick" 
    android:text="Start" /> 


**<TextView 
    android:id="@+id/record" 
    android:layout_width="fill_parent" 
    android:layout_height="500dp" 
    android:layout_below="@+id/time_out" 
    android:layout_above="@+id/btn_start" 
    android:layout_alignParentLeft="true" 
    android:padding="10dp" 
    android:textColor="#FFFFFF" 
    android:textSize="20sp" />** 


<TextView 
    android:id="@+id/time_out" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/relativeLayout1" 
    android:layout_marginTop="37dp" 
    android:gravity="center" 
    android:text="00:00:00" 
    android:textColor="#FFFFFF" 
    android:textSize="60sp" /> 

我想只滾動TextView的大膽。

我不知道如何在這種情況下,使用滾動型。

我該怎麼辦?謝謝:)

+0

你什麼意思,你要滾動一個TextView?你想讓textview裏面的文本在textview高度固定的位置滾動嗎?請解釋更多 –

+0

給我們一些關於答案的反饋。 –

回答

1

您可以滾動使用TextView的滾動字幕屬性(內部的TextView即文本)。

<TextView 
    android:id="@+id/textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:scrollbars="vertical" 
    android:marqueeRepeatLimit="marquee_forever" 
    android:text="@string/hello_world" /> 

和編程

TextView textView = (TextView) findViewById(R.id.textView); 
    textView.setMovementMethod(new ScrollingMovementMethod()); 
+0

它的工作原理!謝謝:) – BaZzi

+0

很酷...你可以接受答案,如果它幫助你... –

0

設置的RelativeLayout的母公司爲滾動型爲滾動型只能有1個直接孩子! 或複製粘貼這個 -

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#001729" 
> 

<ScrollView 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#001729" 
> 

<LinearLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 




<Button 
android:id="@+id/btn_rec" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_alignParentBottom="true" 
android:layout_alignParentLeft="true" 
android:enabled="false" 
android:onClick="myOnClick" 
android:text="Record" /> 

<Button 
android:id="@+id/btn_start" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_above="@+id/btn_rec" 
android:layout_alignParentLeft="true" 
android:onClick="myOnClick" 
android:text="Start" /> 


<TextView 
android:id="@+id/record" 
android:layout_width="fill_parent" 
android:layout_height="500dp" 
android:layout_below="@+id/time_out" 
android:layout_above="@+id/btn_start" 
android:layout_alignParentLeft="true" 
android:padding="10dp" 
android:textColor="#FFFFFF" 
android:textSize="20sp" />** 


<TextView 
android:id="@+id/time_out" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_alignParentLeft="true" 
android:layout_below="@+id/relativeLayout1" 
android:layout_marginTop="37dp" 
android:gravity="center" 
android:text="00:00:00" 
android:textColor="#FFFFFF" 
android:textSize="60sp" /> 

</LinearLayout> 
<ScrollView> 
</RelativeLayout> 

這將滾動全部置於其內的RelativeLayout

+0

這根本不起作用。 –

+0

好的我已編輯 –

+0

它仍然無法正常工作。 –

0

TextView的(一個或多個)更換您的TextView與此

<ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" > 

      <TextView 
       android:id="@+id/textView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 

       android:text="@string/hello_world" /> 
     </LinearLayout> 
    </ScrollView> 
0

你可以用這個替換您的TextView:

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="500dp" 
    android:padding="10dp" 
    android:layout_above="@+id/btn_start" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/time_out" > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <TextView 
      android:id="@+id/record" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:textColor="#FFFFFF" 
      android:textSize="20sp" /> 
    </RelativeLayout> 
</ScrollView> 

我所做的只是將它包裹在一個RelativeLay出來,然後將其包裝在ScrollView中。我還將TextView的佈局屬性放入ScrollView中,因爲現在ScrollView是父級。我選擇了一個RelativeLayout,因爲另一個答案選擇了一個LinearLayout。這並不重要。

注意你可能要玩的幾個屬性。這個想法在那裏。它應該解決。

0

在你的XML(內部的TextView),你可能要設置的屬性:

android:minLines="2" 
android:maxLines="5" 

在您定義的最小和最大行數以這種方式你的textview,只有它會滾動。

在這裏閱讀過:

minLines

maxLines