在ViewPager滚动的TextView [英] Scrollable TextView in ViewPager

查看:134
本文介绍了在ViewPager滚动的TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的TextView 片段 ViewPager 和我想要在的TextView 滚动的文字。出于某种原因,这并不工作和TextView中不会滚动。

I have a TextView inside a Fragment in a ViewPager and I want to make the text in the TextView scrollable. For some reason this doesn't work and the textview does not scroll.

这是我已经试过:

code的片段:

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内的一个片段。当我试图同我的片段这是行不通的。
我也试着在OnStart方法片段类中申请setmovementmethod到TextView的,但没有任何工作。我还以为TextView中有一个与的TextView ID的问题,这是返回null所以我试图将的TextView 文本与的setText();在片段,看看如果类是越来越TextView的ID和它实际工作,所以我不知道为什么setmovementmethod不起作用。

I know this works because I used it to make a tetxview scrollable which is in an activity not in a fragment within a ViewPager. When I tried the same in my fragment it doesn't work. I've also tried to apply setmovementmethod to the textview in onStart method within the fragment class but that did not work either. I also thought the textview there was a problem with the TextView id and it was returning null so I tried to set the TextView text with setText(); in the fragment to see if the class was getting the textview id and it actually worked so I don't know why the setmovementmethod doesn't work.

有谁知道可能是什么问题?

Does anybody know what could be the problem?

感谢您的帮助。

推荐答案

我想通了这个问题。 TextView的是垂直滚动,因为它是继这是从一个片段水平移动到另一个,所以我不得不告诉TextView的片段中的类不听从父母的行为寻呼机查看行为。

I figured out the problem. The TextView was scrolling vertically because it was following the Pager View behavior which was to move horizontally from one fragment to the other so I had to tell the TextView in the Fragment class not to follow the parent behavior.

这是code:

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.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            about.getParent().requestDisallowInterceptTouchEvent(true);
            return false;
        }
    });

     about.setMovementMethod(new ScrollingMovementMethod());  
    return view;

这篇关于在ViewPager滚动的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆