`
haitian235
  • 浏览: 61404 次
  • 性别: Icon_minigender_1
  • 来自: 海南
社区版块
存档分类
最新评论

android代码布局

阅读更多


import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore.Images;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

public class Test extends Activity {
/** Called when the activity is first created. */
LinearLayout linearLayout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

linearLayout= new LinearLayout(this);//线性布局
LinearLayout.LayoutParams layoutParams = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
ImageButton imageButton_1 = new ImageButton(this);
imageButton_1.setLayoutParams(layoutParams);

imageButton_1.setImageDrawable(getResources().getDrawable(
R.drawable.icon));
linearLayout.addView(imageButton_1);
imageButton_1.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
  Dialog dialog = new AlertDialog.Builder(Test.this)
.setTitle("提示")
.setMessage("我是ImageButton1")
.setPositiveButton("确定",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{

}
}).create();//创建按钮
     
      dialog.show();
      }
});
setContentView(linearLayout);
}
public LinearLayout getView(){
return linearLayout;
}
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics