请原谅我我是新的编程为Android。我试图将ImageButton链接到一个名为crafting的类,然后在该类中启动一个名为crafting的xml文件。该按钮似乎没有在avd中做任何事情,但我正在努力查看我的错误在哪里。试图将一个图像按钮链接到一个类Android
下面是代码:
在MainActivity:
package cf.angryman.app;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.button_test);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void SetupCraftingButton() {
ImageButton craftingButton = (ImageButton) findViewById(R.id.crafting);
craftingButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getApplicationContext(), Crafting.class));
}
});
}
}
的工艺加工类:
package cf.angryman.app;
import android.os.Bundle;
import android.app.Activity;
public class Crafting extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.crafting);
}
}
下面是XML代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/home_background" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo"
android:layout_centerInParent="true" />
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="341dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/crafting"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="30dp"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/workbench" />
</LinearLayout>
</ScrollView>
</LinearLayout>
希望你能帮帮我!
感谢,
亚历
你可以发布你的按钮的XML? – 2014-10-26 21:41:49
我用XML更新了原始帖子 – user3407957 2014-10-26 21:44:24