我有一个活动,它有一个带有垂直LinearLayout的ScrollView,它有两个片段,它们是PreferenceFragment实例,如下面的布局文件所示:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_height="wrap_content" android:layout_width="match_parent" > <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" tools:context="com.foo.app.SettingsActivity"> <fragment android:layout_width="wrap_content" android:layout_height="wrap_content" android:name="com.foo.app.SettingsFragment" android:id="@+id/fragment_settings"/> <fragment android:layout_width="wrap_content" android:layout_height="wrap_content" android:name="com.foo.app.NotificationSettingsFragment" android:id="@+id/fragment_notification_settings"/> </LinearLayout>
问题是这两个片段只显示了他们的PreferenceCategory标题,而实际的片段UI是零高度且不可见.奇怪的是,可以单独滚动每个片段并查看丢失的片段UI.就好像每个Fragment都在ScrollView中.
我期望的是两个片段的大小可以包装它们的内容,并且有一个垂直滑块可以滚动包含两个片段的LinearLayout.
如果它是相关的,这两个片段扩展android.preference.PreferenceFragment并且不在布局文件中定义它们的布局.相反,他们加载他们的Preference UI如下:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.pref_notification); }
TIA的帮助.
解决方法
删除外部ScrollView.我有同样的问题,这解决了我.
我还没有在文档中找到它,但显然PreferenceFragment在PreferenceScreen周围提供了自己的ScrollView.以某种方式导致wrap_content高度足够大以显示第一个元素(例如类别标题).
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。