带文本视图的自动滚动滚动视图

问题描述:

为什么我的滚动视图不能自动滚动?我不明白这一点..它只是不动......带文本视图的自动滚动滚动视图

package com.lernapp.src.Activities; 

import java.io.IOException; 

import android.app.Activity; 
import android.content.Context; 
import android.content.Intent; 
import android.graphics.drawable.BitmapDrawable; 
import android.media.AudioManager; 
import android.os.Bundle; 
import android.view.Gravity; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.widget.Button; 
import android.widget.PopupWindow; 
import android.widget.ScrollView; 
import android.widget.TextView; 

import com.lernapp.src.R; 
import com.lernapp.src.Database.DbConfig; 
import com.lernapp.src.Database.LernAppOpenHelper; 

public class StartMenu extends Activity { 

    private ScrollView scroller; 
    private TextView text; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.startmenu); 

     setVolumeControlStream(AudioManager.STREAM_MUSIC); 
     Button infoButton = (Button)findViewById(R.id.startmenubutton4); 

     infoButton.setOnClickListener(new View.OnClickListener() {   
      public void onClick(View v) { 

       LayoutInflater inflater = (LayoutInflater)StartMenu.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       final PopupWindow pw = new PopupWindow(
        inflater.inflate(R.layout.infopopup, null, false), 
        300, 
        400, 
        false); 

       pw.setBackgroundDrawable(new BitmapDrawable());  
       pw.setOutsideTouchable(true);    
       pw.showAtLocation(findViewById(R.id.startmenumain), Gravity.CENTER, 0, 0); 

       View view = inflater.inflate(R.layout.infopopup, null, false); 

       scroller = (ScrollView)view.findViewById(R.id.scroller); 
       text = (TextView)view.findViewById(R.id.scrolltext); 

       scroller.post(new Runnable() { 
        public void run() { 
         scroller.smoothScrollTo(0, text.getBottom()); 
        } 
       }); 

      } 
     }); 

    } 
} 

和popupxml:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:padding="10dip" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#000000" 
    android:id="@+id/scroller"> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginTop="10dip" 
     android:text="test\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\n " 
     android:color="#FFFFFF" 
     android:id="@+id/scrolltext"/> 

</ScrollView> 

为什么不只使用TextView,它可以水平滚动。

android:elippsize="marquee" 
android:scrollHorizontally="true" 
android:focusable="true" 
android:focusableInTouchMode="true" 
+0

因为我想它自动滚动 – krackmoe 2012-01-29 17:02:24

+0

有了这个参数,TExtView自动滚动,就像一个字幕:)。 – Chronos 2012-01-29 18:24:20

+0

嗯..但我怎样才能垂直滚动? – krackmoe 2012-01-29 20:36:59

我认为你需要改变你的身高为wrap_content:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:padding="10dip" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="#000000" 
    android:id="@+id/scroller"> 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dip" 
     android:text="test\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\ntest\n " 
     android:color="#FFFFFF" 
     android:id="@+id/scrolltext"/> 

</ScrollView> 
+0

does not have any effect:/ – krackmoe 2012-01-29 15:59:41

+0

嗯,你也可以尝试设置你的TextView的wrap_content高度以及。 – 2012-01-29 16:18:53

+0

无效...... – krackmoe 2012-01-29 16:24:14