【发布时间】:2014-03-25 17:22:17
【问题描述】:
我在ViewPager 中的Fragment 中有一个TextView,我想让TextView 中的文本可滚动。由于某种原因,这不起作用,并且文本视图不滚动。
这是我尝试过的:
片段中的代码:
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
ViewGroup view = (ViewGroup) inflater.inflate(R.layout.fragment_profile_view, container, false);
about = (TextView) view.findViewById(R.id.profileView_aboutContent_textView);
about.setMovementMethod(new ScrollingMovementMethod());
return view;
}
xml:
<TextView
android:id="@+id/profileView_aboutContent_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/profileView_age_editText"
android:layout_alignBottom="@+id/profileView_age_editText"
android:layout_marginLeft="30dp"
android:layout_toRightOf="@+id/profileView_profileName_textView"
android:scrollbars="vertical"
android:maxLines="5"
android:text="@string/provisional_about_text"
android:textColor="#0066CC" />
我知道这是可行的,因为我用它来制作一个可滚动的 tetxview,它在一个活动中,而不是在 ViewPager 的片段中。当我在我的片段中尝试相同的方法时,它不起作用。
我还尝试将 setmovementmethod 应用于片段类中 onStart 方法中的 textview,但这也不起作用。我还认为 textview 的 TextView id 有问题,它返回 null 所以我尝试使用 setText() 设置 TextView 文本;在片段中查看该类是否正在获取 textview id 并且它确实有效,所以我不知道为什么 setmovementmethod 不起作用。
有人知道可能是什么问题吗?
感谢您的帮助。
【问题讨论】: