我使用的是 Android 中 PageView 设置的默认设置。我想保持简单。默认设置提供了一个 TextView 来放入文本,我的文本从屏幕上消失了。是否可以垂直滚动?
// 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
即可滚动。
ScrollView
引用文档:http://developer.android.com/reference/android/widget/ScrollView.html
编辑示例: 这是您的 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
TextView tView = (TextView)findViewById(R.id.textview);
第二次编辑: 为常规 ScrollView 编辑了上面的示例。另外要添加滑动功能,您需要使用 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 个链接包含非常好的示例!
关于java - 如何基于默认的android PageView制作可滚动 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15013535/