public class Test extends Activity {
RelativeLayout relativeLayout;
ImageView imageView1;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.text);
relativeLayout=(RelativeLayout)findViewById(R.id.relativeLayout);
imageView=(ImageView)findViewById(R.id.imageView);
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
imageView1=new ImageView(Test.this);
imageView1.setLayoutParams(imageView.getLayoutParams());
//imageView1=imageView;
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
imageView1.setBackgroundResource(R.drawable.arrow1);
relativeLayout.addView(imageView1);
Toast.makeText(Test.this, "NEW IMAGE", 1).show();
Toast.makeText(Test.this, "OLD IMAGE", 1).show();
imageView.setVisibility(View.GONE);
imageView=null;
}
}
);XML布局:
android:id="@+id/relativeLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@drawable/aboutus_h" />
这将帮助您完成工作。