1.TextView:
match_parent:当前控件大小和父布局一样
wrap_parent:控件大小刚好包住内容
anroid:gravity="center" :居中
2.EditText:
anroid:hint="Type something here" //提示性文本
anroid:maxLines="2" //最大行数,文本向上滚动
3.ImageView:
anroid:src //picture's location
imageView.setImageResource(R.drawable.flower) //点击按钮切换图片
in android studio the image's format must .png
4.ProgressBar:
设置控件是否可见:
if(progressBar.getVisibility() == View.GONE){
progressBar.setVisibility(View.VISIBLE);
}else{
progressBar.setVisibility(View.GONE);
}
加减进度条:
int progress = progressBar.getProgress();
progress += 10;
progressBar.setProgress(progress);
样式: style="?android:attr/progressBarStyleHorizontal"
5.AlertDialog://弹出提示框
AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
dialog.setTitle
dialog.setMessage
dialog.setCancelable //是否能通过BACK退出对话 FALSE为不允许
//对话中按键监听事件
dialog.setPositiveButton("OK",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
imageView.setImageResource(R.drawable.a1);
}
});
dialog.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
6.Loading框
ProgressDialog.Builder dialog = new ProgressDialog.Builder(MainActivity.this);
dialog.setTitle("this is Dialog");
dialog.setMessage("Loading...");
dialog.setCancelable(false); //在代码中设置好控制取消,调用dismiss()
dialog.show();