我已经在 stackoverflow 上待了一个星期,现在试图找到这个“重叠”问题的答案。
有些人甚至不使用 setContentView()??? 其他人坚持...
我错过了一些东西。
设置活动:
public class SettingsActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.preferences);
getFragmentManager().beginTransaction().replace(R.id.pref_frag_id, new appPreferences()).commit();
}
public static class appPreferences extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
}
}
}
PreferenceFragment 的布局,preferences.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context="${relativePackage}.${activityClass}"
>
<fragment
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/pref_frag_id"
android:name ="com.testng.firstapp.SettingsActivity$appPreferences"
/>
</FrameLayout>
'main' 布局Main.xml,以防我遗漏一些东西:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="${relativePackage}.${activityClass}" >
<ListView
android:id="@+id/lvToDos"
android:layout_width="206dp"
android:layout_height="380dp"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:smoothScrollbar="false"
android:layout_above="@+id/itemEntryView"
android:layout_alignParentTop="true">
</ListView>
<LinearLayout
android:id="@+id/itemEntryView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true" >
<Button
android:id="@+id/btnNewToDo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="editToDoItem"
android:text="@string/new_item"
android:textSize="@dimen/smallTextSize" />
</LinearLayout>
</RelativeLayout>