我在主布局中添加了一个片段。但当我午餐时,应用程序崩溃,错误日志显示:android.view.InflateException: Binary XML file line #16: Error inflating class fragment
。我想我做的一切都是正确的,但我不知道错误在哪里:/。
我的主要布局:
<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:background="@color/dark_grey"
tools:context="com.example.user.unchained.HomesActivity$PlaceholderFragment">
<ListView
android:id="@+id/homeList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp"
android:choiceMode="singleChoice"
android:listSelector="@drawable/list_row_selector" />
<fragment
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:name="com.example.user.unchained.FooterHome"
android:id="@+id/homeFooter"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
tools:layout="@layout/footer_home" />
</RelativeLayout>
我的片段:
<FrameLayout 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:background="#000"
android:id="@+id/homeFooter"
tools:context="com.example.user.unchained.FooterHome">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="What's New ?"
android:textSize="16dip"
android:layout_marginTop="12dip"
android:layout_marginLeft="10dip"
android:drawableLeft="@drawable/status"
android:id="@+id/watsN"
android:textColor="@color/connexion_button"
android:layout_gravity="left|top" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=" | "
android:textSize="25dip"
android:layout_marginTop="6dip"
android:layout_marginLeft="145dip"
android:textColor="@color/connexion_button"
android:layout_gravity="left|top" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Check In"
android:textSize="16dip"
android:layout_marginTop="12dip"
android:layout_marginLeft="165dip"
android:drawableLeft="@drawable/checkin"
android:id="@+id/checkIn"
android:textColor="@color/connexion_button"
android:layout_gravity="left|top" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=" | "
android:textSize="25dip"
android:layout_marginTop="6dip"
android:layout_marginLeft="265dip"
android:textColor="@color/connexion_button"
android:layout_gravity="left|top" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text=" Picture"
android:textSize="16dip"
android:layout_marginTop="12dip"
android:layout_marginLeft="290dip"
android:drawableLeft="@drawable/camera"
android:id="@+id/postPic"
android:textColor="@color/connexion_button"
android:layout_gravity="left|top" />
</FrameLayout>
片段类:
public class FooterHome extends Fragment {
private OnFragmentInteractionListener mListener;
// TODO: Rename and change types and number of parameters
public static FooterHome newInstance() {
FooterHome fragment = new FooterHome();
return fragment;
}
public FooterHome() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.footer_home, container, false);
}
// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnFragmentInteractionListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
public void onFragmentInteraction(Uri uri);
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
public void onFragmentInteraction(Uri uri);
}
}