android控件绑定对象,android控件

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

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

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) {}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值