【发布时间】:2011-10-20 17:39:38
【问题描述】:
我正在使用片段在 Android 3.0 中做一些事情。在其中一个片段中,我需要滚动条。我尝试使用ScrollView,但它没有为我提供片段的滚动条。
如何获得片段的滚动条?
【问题讨论】:
标签: android android-fragments scrollbar scrollview android-3.0-honeycomb
我正在使用片段在 Android 3.0 中做一些事情。在其中一个片段中,我需要滚动条。我尝试使用ScrollView,但它没有为我提供片段的滚动条。
如何获得片段的滚动条?
【问题讨论】:
标签: android android-fragments scrollbar scrollview android-3.0-honeycomb
<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>
【讨论】:
我在官方 Android 资源中找到了一个示例:FragmentLayout。 DetailsFragment 类包含一个 ScrollView,其中包含一个 TextView。
我尝试了这个例子,它在 3.0 SDK Emulator 上运行。 如果它不能解决您的问题,您能否提供更多代码的详细信息?
【讨论】:
或者,您可能更喜欢在 XML 布局文件中实现 ScrollView:How to use ScrollView in Android?
【讨论】:
仅对要滚动的片段使用 ScrollView 标签。它在我的项目中工作。这只是一个建议,因为我不知道您的项目或您想要在屏幕上滚动的内容。
【讨论】:
ScrollView 不能在 Fragment 中使用,因为您不能在同一个父级下为多个 Fragment 充气。您可以使用 RelativeLayout 或 LinearLayout 并将 ScrollView 作为内部布局。
同时检查 com.android.widget 文件夹中的新 FragmentLayout。
【讨论】:
在Android studio中右键点击你的项目并选择New --> Fragment --> Scrolling fragment,所以得到一个新的滚动片段
如果您已经有一个现有的片段,只需检查 android studio 生成的代码并像生成的那样更改您的片段代码。
希望这会有所帮助。
编码愉快!
【讨论】: