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;
}
}
Yes it is very simple, in your xml layout file just make the parent a ScrollView
of whatever you want to be scrollable.
ScrollView
reference doc:http://developer.android.com/reference/android/widget/ScrollView.html
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
Then to get the TextView in your Activity just
TextView tView = (TextView)findViewById(R.id.textview);
2nd Edit: 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!
it is also possible to wrap the entire layout in fragment.xml
in a ScrollView
, see How to add scroll in Fragment. this is also XML based ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With