“UI”的版本间的差异
(→自定义Shape加上阴影shadow之方法) |
(没有差异)
|
2014年6月28日 (六) 08:59的最后版本
UI基础
view类setVisibility()取值
- VISIBLE:0 意思是可见的
- INVISIBILITY:4 意思是不可见的,但还占着原来的空间
- GONE:8 意思是不可见的,不占用原来的布局空间
控件的三个基本属性
这三个基本属性分别是:
- id
- layout_width
- layout_height
id不多说,就是控件的编号,最好是一个控件一个编号以免引用时出现二义性;
layout_ width: 控件的宽度;
layout_ height: 控件的高度。
layout_width和layout_height,都有三个既定值,即”fill_parent”、”match_parent”、” wrap_content”。
前两者含义相同,只是说法不同,如果你的程序需要兼容低版本(2.1以下)Android系统,那就使用”fill_parent”,其含义就是与装载自己的容器相同,即容器有多大空间,控件就占据多大的空间,最大的parent就是手机屏幕。
而最后一个” wrap_content”,就是控件内容有多大,控件就有多大。
除了这三个既定值外,我们还可以用数值任意指定控件大小,但必须有单位。
单位符号
- mm 毫米 与日常生活中我们说的毫米一样,物理意义
- in 英寸 与日常生活中我们说的英寸一样,物理意义
- pt 点 1pt=1/72英寸,物理意义
- px 像素 即屏幕的实际像素
- dp 设备独立像素 使显示的大小与屏幕密度无关,推荐使用
- sp 放大像素 与dp类似,主要用于文字的显示
按钮如何响应点击事件
按钮控件可以在res\layout\main.xml中设置,如:
<Button android:id="@+id/BTN_MYTEST" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="TEST" />
在主java文件的onCreat()函数中,首先使用
super.onCreate(savedInstanceState); setContentView(R.layout.main_view);
将窗口控件布局在界面上。然后使用
Button btnTest = (Button)findViewById(R.id.BTN_MYTEST);
得到界面上的按钮控件。然后使用下面的语句来实现按钮对点击实现的响应:
btnTest.setOnClickListener(this);//若想要按钮响应点击事件,就必须先设置此语句。
CheckBox控件的定义及事件监听
http://blog.sina.com.cn/s/blog_49dffa3b0100xfex.html
Tween动画 (渐变、缩放、位移、旋转)
http://blog.csdn.net/feng88724/article/details/6318430
UI界面随输入法自适应
http://blog.csdn.net/feng88724/article/details/6186037
viewFlipper切换多个layout界面
一 http://www.eoeandroid.com/thread-90753-1-1.html
二 http://www.eoeandroid.com/thread-90754-1-1.html
三 http://www.eoeandroid.com/thread-90759-1-1.html
Layout位移动画
public void next_animator() { DisplayMetrics metric = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metric); int width = metric.widthPixels; // 屏幕宽度(像素) Animation translateAnimation = new TranslateAnimation(width, 0, 0, 0); translateAnimation.setDuration(300); LinearLayout tv_item_type = (LinearLayout) findViewById(R.id.ly_question); tv_item_type.startAnimation(translateAnimation); }
android y axis rotation animation
http://www.inter-fuser.com/2009/08/android-animations-3d-flip.html
滑屏实现
http://blog.csdn.net/qinjuning/article/details/7419207
http://blog.csdn.net/qinjuning/article/details/7247126
自定义Shape加上阴影shadow之方法
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="#792a03" /> <corners android:radius="19dp" /> </shape> </item> <item android:top="1px"> <shape android:shape="rectangle"> <gradient android:startColor="#ffdb8f" android:endColor="#ffdb8f" android:angle="270" /> <padding android:left="5dp" android:top="3dp" android:right="5dp" android:bottom="3dp" /> <corners android:radius="20dp" /> </shape> </item> </layer-list>
将以上xml存成btn_test, 放到res/drawable/目录下。 将该drawable xml设为一个TextView的backgroiund。
<TextView android:background="@drawable/btn_test" android:layout_marginTop="20dip" android:layout_marginLeft="5dip" android:textColor="#792a03" android:text="1天2小时14分20秒" android:layout_width="wrap_content" android:layout_height="wrap_content" />
Dialog对话框
http://www.cnblogs.com/xiaoluo501395377/p/3419398.html
EditText
截获与监听输入事件
http://www.android-study.com/jichuzhishi/154.html
文本控件inputType属性
android:inputType="none"--输入普通字符 android:inputType="text"--输入普通字符 android:inputType="textCapCharacters"--输入普通字符 android:inputType="textCapWords"--单词首字母大小 android:inputType="textCapSentences"--仅第一个字母大小 android:inputType="textAutoCorrect"--前两个自动完成 android:inputType="textAutoComplete"--前两个自动完成 android:inputType="textMultiLine"--多行输入 android:inputType="textImeMultiLine"--输入法多行(不一定支持) android:inputType="textNoSuggestions"--不提示 android:inputType="textUri"--URI格式 android:inputType="textEmailAddress"--电子邮件地址格式 android:inputType="textEmailSubject"--邮件主题格式 android:inputType="textShortMessage"--短消息格式 android:inputType="textLongMessage"--长消息格式 android:inputType="textPersonName"--人名格式 android:inputType="textPostalAddress"--邮政格式 android:inputType="textPassword"--密码格式 android:inputType="textVisiblePassword"--密码可见格式 android:inputType="textWebEditText"--作为网页表单的文本格式 android:inputType="textFilter"--文本筛选格式 android:inputType="textPhonetic"--拼音输入格式 android:inputType="number"--数字格式 android:inputType="numberSigned"--有符号数字格式 android:inputType="numberDecimal"--可以带小数点的浮点格式 android:inputType="phone"--拨号键盘 android:inputType="datetime" android:inputType="date"--日期键盘 android:inputType="time"--时间键盘
文本框始终在输入法之上
简单说来就是采用相对布局。设置下这个布局始终在某个位置,然后设置要显示的内容为居中布局,这样,当输入法弹出的时候,由于中间空间不足,自然就会伸缩。等于说利用安卓本身的机制实现。
EditText自动清空
EditText editText = (EditText)findViewById(R.id.edit_text); editText.getText().clear();
文本框中的输入类型演示
http://www.cqniit.com/item_show.php?id=164&tid=3
设置EditText字体颜色、背景色
view_hello.setBackgroundColor(R.color.white); view_hello.setTextColor(R.color.orange);
获取、设置EditText的文本
public class TestAndriodActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //用EditText前,请先:import android.widget.EditText; //获取文本框1的文本 String str1=""; EditText editText1 =(EditText)findViewById(R.id.editText1); str1=editText1.getText().toString(); //将文本框1的文本赋给文本框2 EditText editText2 =(EditText)findViewById(R.id.editText2); editText2.setText(str1.toCharArray(), 0, str1.length()); } }
Spinner
基本使用方法
http://blog.csdn.net/greenappple/article/details/7046947
设置值
for (int i = 0; i < list.size(); i++) { if (type.equals(list.get(i))) { mySpinner.setSelection(i); } }
选中后显示字体的颜色设置
mySpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { TextView view = (TextView) arg1; view.setTextColor(0xff333333); //设置颜色 } });
设置item字体大小样式
spinner_item.xml
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize="marquee" android:gravity="left" android:padding="4sp" android:singleLine="true" android:textColor="#FFFFFF" android:textSize="16sp" />
activity.java
adapter = new ArrayAdapter<String>(this, R.layout.spinner_item, list);
ListView
Android ListView用法
http://www.iteye.com/topic/540423
Update single item in ListView
http://erikw.eu/android-update-single-item-in-listview/
http://stackoverflow.com/questions/2123083/android-listview-refresh-single-row