1.Dialog大小设置

继承Dialog

Window mwindow = this.getWindow();

WindowManager.LayoutParams lp = mwindow.getAttributes();

lp.x = 0;

lp.y = 0;

lp.height = 800;

lp.width = 800;

mwindow.setAttributes(lp);

lp.alpha = 0.0f; //能够控制添加到此Dialog中控件透明度

this.getWindow().setBackgroundDrawable(new ColorDrawable(0x00000000)); //Dialog背景控制没好使


2.Dialog其他

1.构造函数

MediaDialog继承Dialog

public MediaDialog(Context context) { // context 一般传Activity子类,在消息里new出新的Dialog

super(context);

}

2.  Dialog对象.show()时调用

@Override

protectedvoid onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.media);

}


3.代码布局

Activity的子类

1.view添加

setContentView(view) //Activity的这个界面布局都被一个view占据

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(40, 40);

addContentView(view, params);//Activity上可以添加很多view

在xml里定义了控件就不用addContentView

2.view定位

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(80, 140); //宽、高

params.setMargins(10, 10, 10, 10);//作用未发现:原因自定义的无效要从xml中获取

params.leftMargin = 100;//作用未发现:原因自定义的无效要从xml中获取

3.Margin、padding

http://android.blog.51cto.com/268543/541832


4.图片按钮assets下获取图片资源

ImageView  view = new ImageView(this);

AssetManager asm = getAssets();

InputStream is;

try {

is = asm.open("1.png");

Bitmap p_w_picpath = BitmapFactory.decodeStream(is);

Drawable drawable = newBitmapDrawable(p_w_picpath);

view.setImageBitmap(p_w_picpath);

} catch (IOException e1) {

e1.printStackTrace();

}


ImageView动态定位

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100, 100);

params.setMargins((int) 100, (int) 100, (int) 0, (int) 0);

view.setLayoutParams(params);


监听事件

view.setOnClickListener(new View.OnClickListener() {

@Override

publicvoid onClick(View v) {

Toast.makeText(MainActivity.this, "大声道吗?  是的,他",

Toast.LENGTH_SHORT).show();

}

});


5.显示文字的 TextView (label)

TextView textView = (TextView) findViewById(R.id.test);

textView.setText("打算打算");

textView.setTextSize(40);

textView.setBackgroundColor(Color.BLUE);

textView.setTextColor(Color.BLACK);

textView.setLayoutParams(params);

文字居中xml

android:gravity="center"


6.控件操作

隐藏

xxx.setVisibility(View.INVISIBLE);


7.警告框

AlertDialog.Builder bld = new AlertDialog.Builder(this);
       bld.setMessage("提示");
       bld.setNeutralButton("OK", null);
       bld.create().show();


8.图片按钮

res/layout文件夹里的activity_main.xml

<ImageView

android:src="@drawable/upgrade_app"

android:id="@+id/upgrade_button"

android:onClick="onUpgradeAppButtonClicked"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginRight="20dp"/>


publicvoid onUpgradeAppButtonClicked(View arg0) {}