0

我用 FrameLayout 编写了一个程序,当我单击第一个按钮时,程序显示介绍.xml,但是当我单击第二个按钮时,程序 Force Class。我想是因为我在 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>

产品.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;

        }
    }

};

产品.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;
}

}

4

1 回答 1

2

它是一个错字。product.xml中只有 1 个ButtonT。

于 2013-09-11T05:02:07.077 回答