ck网站,asp网站免费空间,装修公司展厅工艺样板,wordpress手机版本一、常用控件的使用方法
1.TextView
android:gravitycenter 可选值#xff1a;top、bottom、left、right、center等#xff0c;可以用|来同时指定多个值#xff0c;center表示文字在垂直和水平方向都居中
android:textSize 指定文字的大小#…一、常用控件的使用方法
1.TextView
android:gravitycenter 可选值top、bottom、left、right、center等可以用|来同时指定多个值center表示文字在垂直和水平方向都居中
android:textSize 指定文字的大小单位为sp
android:textColor 指定文字的颜色
TextViewandroid:idid/test_viewandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:textThis is TestView/TextViewandroid:idid/test_viewandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:gravitycenterandroid:textThis is TestView/TextViewandroid:idid/test_viewandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:gravitycenterandroid:textSize24spandroid:textColor#00ff00android:textThis is TestView/2.Button
Buttonandroid:idid/buttonandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:textButton/android:textAllCapsfalse 破解系统对Button英文字母自动进行大写转换
Buttonandroid:idid/buttonandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:textButtonandroid:textAllCapsfalse/在main函数中给Button添加监听器
Button button (Button) findViewById(R.id.button);button.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View view) {// 在此处添加逻辑}});3.EditText
EditTextandroid:idid/edit_textandroid:layout_widthmatch_parentandroid:layout_heightwrap_content/android:hintType something here 提示性文字一旦用户输入任何内容提示性的文字就会消失
EditTextandroid:idid/edit_textandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:hintType something here/android:maxLines2 指定EditText的最大行数为两行当输入的内容超过两行时文本就会向上滚动EditText不会继续拉伸
EditTextandroid:idid/edit_textandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:hintType something hereandroid:maxLines2/综合使用EditText和Button完成通过点击按钮来获取EditText中输入的内容 不能按照书上那么写会报错 适当改动的代码
private EditText editText;Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button button (Button) findViewById(R.id.button);editText (EditText) findViewById(R.id.edit_text);button.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View view) {switch (view.getId()) {case R.id.button:String inputText editText.getText().toString();Toast.makeText(MainActivity.this, inputText,Toast.LENGTH_SHORT).show();break;default:break;}}});}4.ImageView
在res下新建文件夹drawable-xhdpi
ImageViewandroid:idid/image_viewandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:srcdrawable/img_1/ 在程序中通过代码动态更改ImageView中的图片 imageView.setImageResource(R.drawable.img_2);
private EditText editText;private ImageView imageView;Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button button (Button) findViewById(R.id.button);editText (EditText) findViewById(R.id.edit_text);imageView (ImageView) findViewById(R.id.image_view);button.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View view) {switch (view.getId()) {case R.id.button:
// String inputText editText.getText().toString();
// Toast.makeText(MainActivity.this, inputText,
// Toast.LENGTH_SHORT).show();imageView.setImageResource(R.drawable.img_2);break;default:break;}}});}5.ProgressBar
在界面上显示一个进度条表示程序正在加载一些数据 所有Android控件都具有可见属性通过android:visibility指定可选值visible,invisible,gone 不指定android:visibility时控件都是可见的。invisible 表示控件不可见但是它仍然占据原来的位置和大小。gone表示空间不仅不可见而且不再占用任何屏幕看空间 代码设置控件的可见性setVisibility()可以传入View.VISIBLEView.INVISIBLEView.GONE
下面几个功能实现有问题 img1为图片一个也看不到下面的进度条 img2为图片显示则都能看到 点击一下按钮让进度条消失再点击一下按钮让进度条出现
public class MainActivity extends AppCompatActivity {private EditText editText;private ImageView imageView;private ProgressBar progressBar;Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button button (Button) findViewById(R.id.button);editText (EditText) findViewById(R.id.edit_text);imageView (ImageView) findViewById(R.id.image_view);progressBar (ProgressBar) findViewById(R.id.progress_bar);button.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View view) {switch (view.getId()) {case R.id.button:
// String inputText editText.getText().toString();
// Toast.makeText(MainActivity.this, inputText,
// Toast.LENGTH_SHORT).show();
// imageView.setImageResource(R.drawable.img_2);if (progressBar.getVisibility() View.GONE) {progressBar.setVisibility(View.VISIBLE);} else {progressBar.setVisibility(View.GONE);}break;default:break;}}});}
给ProgressBar 指定不同的格式
ProgressBarandroid:idid/progress_barandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentstyle?android:attr/progressBarStyleHorizontalandroid:max100/动态改变进度条的进度
Overridepublic void onClick(View view) {switch (view.getId()) {case R.id.button:
// String inputText editText.getText().toString();
// Toast.makeText(MainActivity.this, inputText,
// Toast.LENGTH_SHORT).show();
// imageView.setImageResource(R.drawable.img_2);
// if (progressBar.getVisibility() View.GONE) {
// progressBar.setVisibility(View.VISIBLE);
// } else {
// progressBar.setVisibility(View.GONE);
// }int progress progressBar.getProgress();progress progress 10;progressBar.setProgress(progress);break;default:break;}}6.AlertDialog
public class MainActivity extends AppCompatActivity {private EditText editText;private ImageView imageView;private ProgressBar progressBar;Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button button (Button) findViewById(R.id.button);editText (EditText) findViewById(R.id.edit_text);imageView (ImageView) findViewById(R.id.image_view);progressBar (ProgressBar) findViewById(R.id.progress_bar);button.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View view) {switch (view.getId()) {case R.id.button:
// String inputText editText.getText().toString();
// Toast.makeText(MainActivity.this, inputText,
// Toast.LENGTH_SHORT).show();
// imageView.setImageResource(R.drawable.img_2);
// if (progressBar.getVisibility() View.GONE) {
// progressBar.setVisibility(View.VISIBLE);
// } else {
// progressBar.setVisibility(View.GONE);
// }
// int progress progressBar.getProgress();
// progress progress 10;
// progressBar.setProgress(progress);AlertDialog.Builder dialog new AlertDialog.Builder(MainActivity.this);dialog.setTitle(This is Dialog);dialog.setMessage(Something important.);dialog.setPositiveButton(OK, new DialogInterface.OnClickListener() {Overridepublic void onClick(DialogInterface dialogInterface, int i) {}});dialog.setNegativeButton(Cancel, new DialogInterface.OnClickListener() {Overridepublic void onClick(DialogInterface dialogInterface, int i) {}});dialog.show();break;default:break;}}});}7.ProgressDialog
public class MainActivity extends AppCompatActivity {private EditText editText;private ImageView imageView;private ProgressBar progressBar;Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Button button (Button) findViewById(R.id.button);editText (EditText) findViewById(R.id.edit_text);imageView (ImageView) findViewById(R.id.image_view);progressBar (ProgressBar) findViewById(R.id.progress_bar);button.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View view) {switch (view.getId()) {case R.id.button:
// String inputText editText.getText().toString();
// Toast.makeText(MainActivity.this, inputText,
// Toast.LENGTH_SHORT).show();
// imageView.setImageResource(R.drawable.img_2);
// if (progressBar.getVisibility() View.GONE) {
// progressBar.setVisibility(View.VISIBLE);
// } else {
// progressBar.setVisibility(View.GONE);
// }
// int progress progressBar.getProgress();
// progress progress 10;
// progressBar.setProgress(progress);
// AlertDialog.Builder dialog new AlertDialog.Builder(MainActivity.this);
// dialog.setTitle(This is Dialog);
// dialog.setMessage(Something important.);
// dialog.setPositiveButton(OK, new DialogInterface.OnClickListener() {
// Override
// public void onClick(DialogInterface dialogInterface, int i) {
//
// }
// });
// dialog.setNegativeButton(Cancel, new DialogInterface.OnClickListener() {
// Override
// public void onClick(DialogInterface dialogInterface, int i) {
//
// }
// });
// dialog.show();ProgressDialog progressDialog new ProgressDialog(MainActivity.this);progressDialog.setTitle(This is ProgressDialog);progressDialog.setMessage(Loading...);progressDialog.setCancelable(true);progressDialog.show();break;default:break;}}});}
}二、四种基本布局 1.线性布局
android:orientation属性指定控件的排列方向垂直排列是vertical水平排列是horizontal
android:layout_gravity 指定控件在布局中的对齐方式
android:layout_weight 使用比例的方式来指定控件的大小
dp是Android用于指定控件大小和间距等属性的单位
2.相对布局
控件相对于父布局进行定位
android:layout_alignParentLefttrue
android:layout_alignParentToptrue
android:layout_centerInParenttrue控件相对于控件进行定位
android:layout_aboveid/button_2
android:layout_toLeftOfid/button_2
android:layout_belowid/button_23.帧布局
所有控件默认摆放在布局的左上角可以使用layout_gravity属性来指定控件在布局中的对齐方式
4.百分比布局
添加百分比布局依赖implementation androidx.percentlayout:percentlayout:1.0.0 文章转载自: http://www.morning.nykzl.cn.gov.cn.nykzl.cn http://www.morning.rqxhp.cn.gov.cn.rqxhp.cn http://www.morning.kwnbd.cn.gov.cn.kwnbd.cn http://www.morning.yjfzk.cn.gov.cn.yjfzk.cn http://www.morning.rmqmc.cn.gov.cn.rmqmc.cn http://www.morning.rhmpk.cn.gov.cn.rhmpk.cn http://www.morning.uycvv.cn.gov.cn.uycvv.cn http://www.morning.tsnmt.cn.gov.cn.tsnmt.cn http://www.morning.qmxsx.cn.gov.cn.qmxsx.cn http://www.morning.hnpkr.cn.gov.cn.hnpkr.cn http://www.morning.jcbmm.cn.gov.cn.jcbmm.cn http://www.morning.btblm.cn.gov.cn.btblm.cn http://www.morning.zmyzt.cn.gov.cn.zmyzt.cn http://www.morning.kgjyy.cn.gov.cn.kgjyy.cn http://www.morning.cnwpb.cn.gov.cn.cnwpb.cn http://www.morning.tyrlk.cn.gov.cn.tyrlk.cn http://www.morning.simpliq.cn.gov.cn.simpliq.cn http://www.morning.djpzg.cn.gov.cn.djpzg.cn http://www.morning.rkqkb.cn.gov.cn.rkqkb.cn http://www.morning.fpkdd.cn.gov.cn.fpkdd.cn http://www.morning.rnxs.cn.gov.cn.rnxs.cn http://www.morning.rjkfj.cn.gov.cn.rjkfj.cn http://www.morning.bgzgq.cn.gov.cn.bgzgq.cn http://www.morning.rwhlf.cn.gov.cn.rwhlf.cn http://www.morning.rxwfg.cn.gov.cn.rxwfg.cn http://www.morning.nlysd.cn.gov.cn.nlysd.cn http://www.morning.bhznl.cn.gov.cn.bhznl.cn http://www.morning.mmzhuti.com.gov.cn.mmzhuti.com http://www.morning.rlwgn.cn.gov.cn.rlwgn.cn http://www.morning.ykwbx.cn.gov.cn.ykwbx.cn http://www.morning.bchhr.cn.gov.cn.bchhr.cn http://www.morning.pwlxy.cn.gov.cn.pwlxy.cn http://www.morning.gsyns.cn.gov.cn.gsyns.cn http://www.morning.nsyzm.cn.gov.cn.nsyzm.cn http://www.morning.jjzrh.cn.gov.cn.jjzrh.cn http://www.morning.xqmd.cn.gov.cn.xqmd.cn http://www.morning.qbdsx.cn.gov.cn.qbdsx.cn http://www.morning.wwgpy.cn.gov.cn.wwgpy.cn http://www.morning.rmqlf.cn.gov.cn.rmqlf.cn http://www.morning.lffgs.cn.gov.cn.lffgs.cn http://www.morning.rczrq.cn.gov.cn.rczrq.cn http://www.morning.nslwj.cn.gov.cn.nslwj.cn http://www.morning.bbyqz.cn.gov.cn.bbyqz.cn http://www.morning.mxdhy.cn.gov.cn.mxdhy.cn http://www.morning.kqbjy.cn.gov.cn.kqbjy.cn http://www.morning.xqbbc.cn.gov.cn.xqbbc.cn http://www.morning.nfqyk.cn.gov.cn.nfqyk.cn http://www.morning.wfbnp.cn.gov.cn.wfbnp.cn http://www.morning.lfdmf.cn.gov.cn.lfdmf.cn http://www.morning.rpwm.cn.gov.cn.rpwm.cn http://www.morning.cprbp.cn.gov.cn.cprbp.cn http://www.morning.jwxmn.cn.gov.cn.jwxmn.cn http://www.morning.xphls.cn.gov.cn.xphls.cn http://www.morning.dkfrd.cn.gov.cn.dkfrd.cn http://www.morning.hgcz.cn.gov.cn.hgcz.cn http://www.morning.drggr.cn.gov.cn.drggr.cn http://www.morning.ywgrr.cn.gov.cn.ywgrr.cn http://www.morning.pypbz.cn.gov.cn.pypbz.cn http://www.morning.chzqy.cn.gov.cn.chzqy.cn http://www.morning.pxdgy.cn.gov.cn.pxdgy.cn http://www.morning.qjldz.cn.gov.cn.qjldz.cn http://www.morning.ntgjm.cn.gov.cn.ntgjm.cn http://www.morning.hnhgb.cn.gov.cn.hnhgb.cn http://www.morning.ksjnl.cn.gov.cn.ksjnl.cn http://www.morning.wjxtq.cn.gov.cn.wjxtq.cn http://www.morning.dplmq.cn.gov.cn.dplmq.cn http://www.morning.nqrlz.cn.gov.cn.nqrlz.cn http://www.morning.bktzr.cn.gov.cn.bktzr.cn http://www.morning.syqtt.cn.gov.cn.syqtt.cn http://www.morning.zcmpk.cn.gov.cn.zcmpk.cn http://www.morning.lmqfq.cn.gov.cn.lmqfq.cn http://www.morning.rxkl.cn.gov.cn.rxkl.cn http://www.morning.addai.cn.gov.cn.addai.cn http://www.morning.qtxwb.cn.gov.cn.qtxwb.cn http://www.morning.smszt.com.gov.cn.smszt.com http://www.morning.qpmwb.cn.gov.cn.qpmwb.cn http://www.morning.mrqwy.cn.gov.cn.mrqwy.cn http://www.morning.nlywq.cn.gov.cn.nlywq.cn http://www.morning.gkjyg.cn.gov.cn.gkjyg.cn http://www.morning.mzwqt.cn.gov.cn.mzwqt.cn