Android学习(6)-UI介绍
来源:互联网 发布:php curl get 数据 编辑:程序博客网 时间:2024/05/29 13:36
界面设计和功能开发同样重要,界面美观的应用程序可以大大增加用户粘性,还能帮助我们吸引到更多的新用户。为了以后做出比较复杂的界面,应该以XML为基础编写界面。把界面化定制界面看成是一个预览工具。
(1) TextView
<TextView
android: id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" //宽度和高度:match_parent fill_parent,这两个差不多,推荐第一个。 wrap_content表示控件大小取决于包含内容的大小。
android:gravity="center" //字体位置
android:textSize="24sp"
android:textColor="#00ff00"
android:text="This is textView"
/>
(2) Button
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
/>
在onCreate中可以通过以下代码设置按钮事件:
Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(new OnClickListener({
public void onClick(View v){
}
})
);
以上是通过匿名类的方式注册监听器,也可以使用实现接口来做。
public class SomeActivity extends Activity implements OnClickListener{
public void onClick(View v){
switch(v.getId()){
case R.id.button:
......
}
}
}
(3) EditText
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Type something here" //文本框提示内容
android:maxLines="2" //文本框可显示最大行数
/>
代码中获取文本框输入内容:
EditText editText = (EditText)findViewById(R.id.edit_text);
String inputText = editText.getText().toString();
(4) ImageView
<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
/>
在代码中修改图片:
ImageView imageView = (ImageView)findViewById(R.id.image_view);
imageView.setImageResource(R.drawable.jelly_bean);
(5) ProgressBar
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
设置进度条可见不可见:
private ProgressBar progressBar;
protected void onCreate(){
progressBar=(ProgressBar)findViewById(R.id.progress_bar);
button.setOnClickListener(this);
}
public void onClick{
if(progressBar.getVisibility() == View.GONE)
progressBar.setVisibility(View.VISIBLE);
}
以上进度条是旋转型圆圈,可以改成是水平进度条。设置为:
style="?android:attr/progressBarStyleHorizontal"
android:max="100"
可以通过代码改变其进度:
int progress = progressBar.getProgress();
progress += 10;
progressBar.setProgress(progress);
(6) AlertDialog
alertdialog用于提示一些非常重要的内容或者警告信息。
AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
dialog.setTitle("...");
dialog.setMessage("...");
dialog.setCancleable(false);
dialog.setPositiveButton("OK",new DialogInterface.OnClickListener(){
public void onClick(...){...}
});
(7) ProgressDialog弹出对话框中的是进度条。
ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.setTitle(...);
progressDialog.setMessage(...);
progressDialog.setCancelable(true);
progressDialog.show();
(8)px pt dp sp
px和pt是像素和磅值,用于pc时候限制大小和文字等不错,但是手机屏幕小,影响就比较大。
dp sp是谷歌提出的用于手机上的单位,以单位密度为准,比较好用。
- Android学习(6)-UI介绍
- android--UI介绍(未更新完)
- Android UI学习(二)
- Android UI学习(一)
- Android UI学习(二)
- android学习笔记(三)基础UI组件1——按钮,文本框,CheckBox,Radiobutton介绍
- Android Honeycomb Preview UI介绍
- UI----Android主流屏幕分辨率介绍
- Android目录介绍&UI简介
- android开发之UI介绍
- 【Android初学者】UI组件 介绍
- LibGdx UI编辑器 OverLap2D 学习(1) 介绍
- android UI学习笔记(布局)
- Android UI学习 - 对话框 (AlertDialog & ProgressDialog)
- android学习十七(更新UI)
- Android学习(7)-UI布局
- Android UI控件学习笔记(二)
- Android学习笔记(三)UI
- Android增加Happy Touch触摸屏支持
- Appium之java API(01)-AppiumDriver
- WAY BACK INTO JAVA
- Apache运行机制剖析
- [leetcode] Regular Expression Matching
- Android学习(6)-UI介绍
- 数据库事务隔离级别
- appium之java API(2) -TouchAction
- 利用Jsoup爬取天猫列表页数据
- spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解实例详解(二)
- Address already in use: JVM_Bind
- IOS事件传递之hitTest:withEvent - IOS开发...
- Android Studio 的一些简单配置
- 外连接和内连接