为什么我的Scrollview不能自动滚动?我不明白......它只是不动......
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>
答案 0 :(得分:1)
为什么不使用TextView,它可以水平滚动。
android:elippsize="marquee"
android:scrollHorizontally="true"
android:focusable="true"
android:focusableInTouchMode="true"
答案 1 :(得分:0)
我认为你需要将你的身高改为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>