我目前正在开发一个应用程序。当我在 android 手机中安装 my_app 并在水平视图中旋转时,我的按钮丢失了,请帮忙!!在此先感谢我的Java编码是:
public class Draw extends Activity {
ImageView iv1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final DrawView drawView = new DrawView(this);
setContentView(R.layout.draw);
FrameLayout frm_layout=(FrameLayout) findViewById(R.id.main_frame);
iv1=(ImageView) findViewById(R.id.imageView1);
frm_layout.addView(drawView);
Intent myIntent = getIntent(); // this is just for example purpose
String test=myIntent.getExtras().getString("guided");
if(test.equals("1"))
{
iv1.setImageResource(R.drawable.untitled);
iv1.setAlpha(100);
}
else
{
//iv1.setImageResource(null);
}
//Toast.makeText(getApplicationContext(), test.toString(), 2000).show();
Button btn_undo=(Button) findViewById(R.id.button1);
btn_undo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
drawView.onClickUndo();
}
});
Button btn_redo=(Button) findViewById(R.id.button2);
btn_redo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
drawView.onClickRedo();
}
});
}
}
我的 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="@android:color/white" >
<FrameLayout
android:id="@+id/main_frame"
android:layout_width="fill_parent"
android:layout_height="472dp"
android:background="@android:color/white" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</FrameLayout>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Redo" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Undo" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Save" />
</RelativeLayout>
</LinearLayout>