Android 带textview的自动可滚动滚动滚动视图

Android 带textview的自动可滚动滚动滚动视图,android,android-layout,Android,Android Layout,为什么我的滚动视图不能自动滚动?我不明白。。它就是不动 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.

为什么我的滚动视图不能自动滚动?我不明白。。它就是不动

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>

我想你需要改变你的高度来包装内容:

<?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> 

为什么不仅使用文本视图,它还可以水平滚动

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

嗯,你也可以试着把你的文本视图设置为内容高度。啊,误解了这个问题!你的scroller.post可以运行吗?好像根本没有调用该post。。但是我在这个线程中添加了一个logcat输出。。它被调用过一次…因为我想让它自动滚动,参数是TExtView自动滚动的,就像一个选框:).Mh。。但是我怎样才能垂直滚动呢?