第一次作业要交主界面,而我今天写的是欢迎界面,囧,不过这个欢迎界面搞了我整整两天。都说万事开头难,这话真不错!各种bug,各种莫名其妙啊,不过还好,终于把这个欢迎界面弄出来了!撒花 -。=
-----------------------------------------------------------------------------
我的欢迎界面是一个图片和两行文字组成,也就是有一个ImageView和两个TextView组成,很简单,不过对于一个新人来说,布局还是很有难度的。研究了很多关于布局的东东,最后界面如图:
(莫吐槽)
xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical">
<ImageView
android:id="@+id/image01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/mrexpen" />
<TextView
android:id="@+id/text01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/image01"
android:layout_gravity="center"
android:text="I am Mr.Expense -.="
android:textSize="25dp"
android:textStyle="bold" />
<TextView
android:id="@+id/text02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/text01"
android:layout_gravity="center"
android:text="Better life,better future!"
android:textSize="15dp"
android:paddingTop="2dp"
android:textColor="#808000"
android:typeface="monospace" />
</LinearLayout>
说明:
1、我用的是LinearLayout,这个layout默认的orientation是horizonal的,所以我要垂直的话必须指定vertical。
2、看到有的书籍上都用fill_parent,查资料才发现就是match_parent。。。
3、gravity:组件的子组件在组件的位置
layout_gravity:组件自身在父组件的位置
4、center_horizonal或者center_vertical有时候会失效,取决于orientation的设置值,但是我用center的话,总有个居中的。呵呵
Activity:
public class Initialize extends Activity{
private ImageView imageView;
private TextView textViewOne;
private TextView textViewTwo;
public void onCreate(Bundle savedInstanceState){
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.initialize);
imageView=(ImageView)this.findViewById(R.id.image01);
textViewOne=(TextView)this.findViewById(R.id.text01);
textViewTwo=(TextView)this.findViewById(R.id.text02);
new CountDownTimer(2000,1000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
startActivity(new Intent(Initialize.this, Main.class));
overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out);
finish();
}
}.start();
}
}
说明:
1、requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
是用来全屏的,不然上面会有个title,会很奇怪。。。
也可以在Manifest.xml中设置,我还是直接在activity中设置,看个人习惯
2、new CountDownTimer(2000,1000)
是个倒计时,重写它,2秒后会执行onFinish()
3、Main.class是主界面,但是还木有写来
4、overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out);
是淡入淡出特效,还有其他特效网上都可以搜得到,先拿一个来用用看,还不错吧
关于我遇到的问题:
我不是直接拖得那种,布局很苦恼,各种布局都用过,RelativeLayout也可以实现同样的效果。但是总感觉不稳定,这是第六感吗?而且布局细节也难,自己接触的布局类别太少,很多参数都还没碰到,以后慢慢积累吧
还有就是模拟器启动的好慢啊,还经常罢工。。。果然还是得在真机上试验!
----------------------------------------
4.21南京