手机ui界面设计PHP代码,【Android开发】用户界面设计-在代码中控制UI界面

效果图:

b4d82380d81f01afabe4082dde598ed3.png

9512b8fc63de98d79ff30fd52614abfd.png

实现方法:

MainActivity: package com.example.test; import android.app.ActionBar.LayoutParams; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.util.TypedValue; import android.view.Gravity; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.TextView; public class MainActivity extends Activity { public TextView text2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //使用代码布局就不用设置下面这句 //setContentView(R.layout.main); FrameLayout frameLayout=new FrameLayout(this);//创建帧布局管理器 //设置背景 frameLayout.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.backgroud)); //设置在Activity中显示frameLayout setContentView(frameLayout); //设置两个TextView控件 TextView text1=new TextView(this); text1.setText("在代码中控制UI界面");//设置显示文字 text1.setTextSize(TypedValue.COMPLEX_UNIT_PX,24);//设置文字大小,单位为像素 text1.setTextColor(Color.rgb(1, 1, 1));//设置文字颜色 frameLayout.addView(text1);//将text1添加到布局管理器中 text2=new TextView(this); text2.setText("单击进入游戏");//设置显示文字 text2.setTextSize(TypedValue.COMPLEX_UNIT_PX,24);//设置文字大小,单位为像素 text2.setTextColor(Color.rgb(1, 1, 1));//设置文字颜色 LayoutParams params=new LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);//创建保存布局参数的对象 params.gravity=Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;//设置居中显示 text2.setLayoutParams(params);//设置布局参数 text2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(MainActivity.this).setTitle("系统提示")//设置对话框的标题 .setMessage("游戏有风险,进入需谨慎,真的要进入吗?") .setPositiveButton("确定", //为确定按钮添加单击事件 new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.i("3.2", "进入游戏");//输出消息日志 } }).setNegativeButton("退出", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.i("3.2", "退出游戏");//输出消息日志 finish(); } }).show(); } }); frameLayout.addView(text2); } }

main.xml设置frameLayout布局就可以了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值