本文介绍了如何在Fragment中加载PreferenceFragment的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将主要活动分为两个片段,

I have divided main activity in two Fragments,

上半部分从xml加载Button,

the upper Portion loads the Button from xml,

&我想在thr下部分加载 PreferenceFragment

& i want to load PreferenceFragment in thr Lower Portion ,

该怎么做??

我尝试使用下面的代码片段中的以下代码直接调用Settings.class,该类直接扩展了PreferenceFragment

I tried calling the Settings.class which extends PreferenceFragment directly using the following code in my Lower Portion Fragment

getFragmentManager().beginTransaction().replace(android.R.id.content,new Settings ()).commit();

这称为PreferenceFragment,但它重叠了上半部分,

That calls the PreferenceFragment but it Overlaps the upper Portion,

我正在努力实现这样的目标

I am trying to achieve something like this

推荐答案

您可以在活动的布局文件中声明片段.

You can declare the fragments in the activity's layout file.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <fragment android:name="com.example.news.ArticleListFragment"
        android:id="@+id/list"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="match_parent" />
    <fragment android:name="com.example.news.ArticleReaderFragment"
        android:id="@+id/viewer"
        android:layout_weight="2"
        android:layout_width="0dp"
        android:layout_height="match_parent" />
</LinearLayout>

这篇关于如何在Fragment中加载PreferenceFragment的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 11:04