Yog Guru
Yog Guru

Reputation: 2104

ScrollView in Fragment

I am doing some stuff in Android 3.0 with fragments. In one of the fragments, I need the scroll bar. I tried using a ScrollView, but it does not give me a scroll bar for the fragment.

How do I get a scroll bar for a fragment?

Upvotes: 5

Views: 32365

Answers (6)

Adeeksha Sathsara
Adeeksha Sathsara

Reputation: 183

In Android studio right click your project and select New --> Fragment --> Scrolling fragment, so get a new scrolling fragment

If you already have an existing fragment, just check that android studio generated code and change your fragment code like the generated one.

Hope this helped.

Happy coding!

Upvotes: 0

Sumukh Bhandarkar
Sumukh Bhandarkar

Reputation: 384

ScrollView cannot be used in a Fragment, since you cannot inflate many fragments under the same parent. You could rather use RelativeLayout or LinearLayout and keep ScrollView as inner layout.

Also checkout the new FragmentLayout in com.android.widget folder.

Upvotes: 0

jobin philip
jobin philip

Reputation: 53

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

//enclose your code for contents of fragment here. This helped me to add scroll view to the fragment





</ScrollView>

Upvotes: 4

john kiran
john kiran

Reputation: 1

Use ScrollView tags for only fragments, which you want to scroll. It is working in my project. This is just a suggestion because I don't know your project or what you want to scroll on the screen.

Upvotes: 0

Rob
Rob

Reputation: 778

Alternatively, you might prefer to just implement the ScrollView in an XML layout file: How to use ScrollView in Android?

Upvotes: 0

Niqo
Niqo

Reputation: 1072

I've found an example in the official Android resources: FragmentLayout. The class DetailsFragment contains a ScrollView which contains a TextView.

I tried the example and it's working on 3.0 SDK Emulator. If it doesn't fix your problem, can you give more details of your code ?

Upvotes: 1

Related Questions