如何基于默认的android PageView制作可滚动的片段 [英] How to make a scrollable fragment based on the default android PageView

查看:330
本文介绍了如何基于默认的android PageView制作可滚动的片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android中PageView设置的默认设置。我想保持简单。默认设置提供TextView以放入文本,我的文本离开屏幕。是否可以垂直制作此卷轴?

I am using the default setup from the PageView setup in Android. I want to stay very simple. The default setup provides a TextView to put text in, and my text goes off the screen. Is it possible to make this scroll vertically?

// edited to make the code appear in the code block
public class DayFragment extends Fragment {
    /**
     * The fragment argument representing the section number for this
     * fragment.
     */
    public static final String ARG_SECTION_NUMBER = "section_number";

    public DayFragment() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // Create a new TextView and set its text to the fragment's section
        // number argument value.
        TextView tView = new TextView(getActivity());
        if(getArguments().getInt(ARG_SECTION_NUMBER) > 1){
            tView.setText(getAllMeals(getArguments().getInt(
                    ARG_SECTION_NUMBER)-1));}
        else {
            getMeal();
            tView.setText(message);
        }
        return tView;
    }
}


推荐答案

是它非常简单,在你的xml布局文件中,只需让父 ScrollView 即可滚动。

Yes it is very simple, in your xml layout file just make the parent a ScrollView of whatever you want to be scrollable.

ScrollView 参考文档: http:// developer .android.com / reference / android / widget / ScrollView.html

编辑示例:
以下是XML示例。

Edit sample: Here is a sample of your XML.

...rest of xml
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <TextView
        android:id="@+id/textview"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"/>
 </ScrollView> ...rest of xml

然后在你的Activity中获取TextView

Then to get the TextView in your Activity just

TextView tView = (TextView)findViewById(R.id.textview);

第二编辑:
编辑以上常规滚动视图的示例。另外,要添加滑动功能,您需要使用ViewPager( http:// developer .android.com / reference / android / support / v4 / view / ViewPager.html )和FragmentPagerAdapter( http://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html )。官方开发者文档的2个链接包含非常好的示例!

2nd Edited above sample for a regular scrollview. Also to add the swiping functionality, you will want to use a a ViewPager(http://developer.android.com/reference/android/support/v4/view/ViewPager.html) and a FragmentPagerAdapter(http://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html). The 2 links to official developer documents contain really great examples!

这篇关于如何基于默认的android PageView制作可滚动的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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