我用FrameLayout编写程序,当我点击第一个按钮时,程序显示了introduction.xml但是当我点击第二个按钮时,程序强制类。我认为因为我在product.xml文件中使用Button,因为当我将按钮更改为imageView时,程序运行良好。为什么?怎么解决这个问题?
运行时错误:
binary xml file line #7 error inflating class Button in android
MainActivity.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@color/white">
<TextView
android:id="@+id/logoText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/dark_blue"
android:text="@string/logotxt"/>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0"
android:layout_gravity="bottom">
<FrameLayout
android:id="@+id/frameLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:layout_weight="1"/>
<Button android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/b1"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:text="@string/btn1"
/>
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/b2"
android:layout_toRightOf="@id/btn1"
android:layout_alignBottom="@id/btn1"
android:text="@string/btn2"
/>
<Button android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/b3"
android:layout_toRightOf="@id/btn2"
android:layout_alignBottom="@id/btn1"
android:text="@string/btn3"
/>
<Button android:id="@+id/btn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/b4"
android:layout_toRightOf="@id/btn3"
android:layout_alignBottom="@id/btn1"
android:text="@string/btn4"
/>
</RelativeLayout>
</LinearLayout>
product.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Buton
android:id="@+id/android_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/red"
android:text="@string/android"/>
</LinearLayout>
MainActivity.java:
public class MainActivity extends FragmentActivity {
public String fonts="BZar.ttf";
TextView logoText;
Button btnIntroduce;
Button btnProduct;
Button btnContact;
Button btnMore;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setFont();
btnIntroduce.setOnClickListener(onClickListener);
btnProduct.setOnClickListener(onClickListener);
}
private OnClickListener onClickListener=new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
FragmentManager fm=getSupportFragmentManager();
FragmentTransaction ft=fm.beginTransaction();
switch(v.getId()){
case R.id.btn4:
Log.e("button", "4click");
//ft.add(R.id.frameLayout, new Introduce());
ft.setCustomAnimations(R.anim.push_right_in, R.anim.push_left_out);
ft.replace(R.id.frameLayout, new Introduce());
ft.commit();
break;
case R.id.btn3:
Log.e("button", "3Click");
ft.setCustomAnimations(R.anim.push_right_in, R.anim.push_left_out);
ft.replace(R.id.frameLayout, new Product());
ft.commit();
break;
}
}
};
Product.java:
public class Product extends Fragment{
public String fonts="BZar.ttf";
Typeface face;
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
View view=inflater.inflate(R.layout.product, container, false);
face=Typeface.createFromAsset(getActivity().getAssets(), "font/"+fonts+"");
/*Button btnAndroid=(Button)view.findViewById(R.id.android_btn);
btnAndroid.setTypeface(face);
String android=(String)btnAndroid.getText().toString();
btnAndroid.setText(PersianReshape.reshape(android));*/
return view;
}
}
答案 0 :(得分:1)
这是一个错字。 product.xml
Button
只有{T}。{/ 1>