Android 界面设计.docx

上传人:b****8 文档编号:29804802 上传时间:2023-07-27 格式:DOCX 页数:21 大小:331.45KB
下载 相关 举报
Android 界面设计.docx_第1页
第1页 / 共21页
Android 界面设计.docx_第2页
第2页 / 共21页
Android 界面设计.docx_第3页
第3页 / 共21页
Android 界面设计.docx_第4页
第4页 / 共21页
Android 界面设计.docx_第5页
第5页 / 共21页
点击查看更多>>
下载资源
资源描述

Android 界面设计.docx

《Android 界面设计.docx》由会员分享,可在线阅读,更多相关《Android 界面设计.docx(21页珍藏版)》请在冰豆网上搜索。

Android 界面设计.docx

Android界面设计

Androidtext文字阴影设置

    android:

id="@+id/text" 

    android:

layout_width="wrap_content"

    android:

layout_height="wrap_content" 

    android:

text="text1"

    android:

textSize="35dip" 

    android:

textStyle="bold" 

    android:

textColor="#FFFFFF"

    android:

shadowColor="#ff000000" 

    android:

shadowDx="2" 

    android:

shadowDy="2"

    android:

shadowRadius="1" 

    />

关于android文字阴影,共有四个属性可以设置:

android:

shadowColor:

阴影颜色

android:

shadowDx:

阴影x方向位移

android:

shadowDy:

阴影y方向位移

android:

shadowRadius:

阴影的半径

注意:

阴影的半径必须设,为0时没有效果。

android:

shadowColor="#ff000000"//前两位为透明度

android:

shadowDx="2"

android:

shadowDy="0"

android:

shadowRadius="1"//这一项是必须要有的数字越大阴影会越透明和扩散

 

Android基础之自定义Activity间的切换动画

Android中默认的2个Activity间的切换是左右形式的,你是否已经看的厌烦,或者觉得他不够个性,Android中提供了一种方法,可以自定义这个动画效果。

先看下效果图:

产生动画效果主要是这行代码overridePendingTransition(R.anim.scale,R.anim.alpha);

看代码部分:

1、自定义2个Activity和2个动画效果

淡入淡出效果R.anim.alpha

?

1

2

3

4

5

6

7

8

9

10

11

xmlversion="1.0"encoding="utf-8"?

>

android="

    android:

interpolator="@android:

anim/accelerate_interpolator">

    

        android:

id="@+id/alpha" 

        android:

fromAlpha="1.0"

        android:

toAlpha="0.0" 

        android:

duration="2000" 

        />

放大缩小效果R.anim.scale

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

xmlversion="1.0"encoding="utf-8"?

>

android="

    android:

interpolator="@android:

anim/accelerate_interpolator">

    

        android:

startOffset="2000" 

        android:

duration="2000"

        android:

fromXScale="0.0" 

        android:

toXScale="1.0" 

        android:

fromYScale="0.0"

        android:

toYScale="1.0" 

        android:

pivotX="50%" 

        android:

pivotY="50%" 

        />

2、主要代码MainActivity.java

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

packagecom.yin.change;

  

importandroid.app.Activity;

importandroid.content.Intent;

importandroid.os.Bundle;

importandroid.view.View;

importandroid.view.View.OnClickListener;

importandroid.widget.Button;

  

publicclassMainActivityextendsActivity{

    privateButtonmButton;

  

    publicvoidonCreate(BundlesavedInstanceState){

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        mButton=(Button)findViewById(R.id.mButton);

        mButton.setOnClickListener(newOnClickListener(){

  

            publicvoidonClick(Viewv){

                Intentintent=newIntent();

                intent.setClass(MainActivity.this,Second.class);

                startActivity(intent);

  

                //添加必须在StartActivity启动之后

                //第一个参数为:

第二个Activity启动时的效果

                //第二个参数为:

第一个Activity退出时的效果

                overridePendingTransition(R.anim.scale,R.anim.alpha);

  

            }

        });

  

    }

}

Android按钮设置文字变色

1

asButton.setTextColor(R.color.white);

这种直接把颜色的ID进去,发现文字都变成黑色的了,所以需要使用setTextColor(ColorStateListcolors)这个方法,传入ColorStateList对象。

?

1

2

ColorStateListwhiteColor=getResources().getColorStateList(R.color.white);

asButton.setTextColor(whiteColor);

这样文字就可以变颜色了。

ColorStateList对象可以在XML中定义,像color一样使用,它能根据它应用到的View对象的状态实时改变颜色。

例如,Button可以存在多种状态(pressed、focused或other),如果使用ColorStateList,你就能为它的每个状态提供不同的颜色。

AndroidLayoutInflater的使用

大家好我们这一节讲的是AndroidLayoutInflater的使用,在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById(),不同的是LayoutInflater是用来找layout下xml布局文件,并且实例化!

而findViewById()是找具体xml下的具体widget控件(如:

Button,TextView等)。

为了让大家更容易理解我做了一个简单的Demo,主布局main.xml里有一个TextView和一个Button,当点击Button,出现Dialog,而这个Dialog的布局方式是我们在layout目录下定义的custom_dialog.xml文件(里面左右分布,左边ImageView,右边TextView)。

效果图如下:

下面我将详细的说明Demo的实现过程:

1、新建一个Android工程,我们命名为LayoutInflaterDemo.

2、修改main.xml布局,里面主要在原来基础上增加了一个Button.代码如下:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

xmlversion="1.0"encoding="utf-8"?

>

android="

    android:

orientation="vertical" 

    android:

layout_width="fill_parent"

    android:

layout_height="fill_parent">

    

        android:

layout_width="fill_parent"

        android:

layout_height="wrap_content" 

        android:

text="@string/hello"/>

    

        android:

id="@+id/button" 

        android:

layout_width="wrap_content"

        android:

layout_height="wrap_content" 

        android:

text="ShowCustomDialog"/>

3、定义对话框的布局方式,我们在layout目录下,新建一个名为custom_dialog.xml文件,具体代码如下:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

xmlversion="1.0"encoding="utf-8"?

>

android="

    android:

orientation="horizontal" 

    android:

layout_width="fill_parent"

    android:

layout_height="fill_parent" 

    android:

padding="10dp">

    

        android:

id="@+id/image" 

        android:

layout_width="wrap_content"

        android:

layout_height="fill_parent" 

        android:

layout_marginRight="10dp"/>

    

        android:

id="@+id/text" 

        android:

layout_width="wrap_content"

        android:

layout_height="fill_parent" 

        android:

textColor="#FFF"/>

4、修改主程序LayouInflaterDemo.java代码如下:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

packagecom.android.tutor;

  

importandroid.app.Activity;

importandroid.app.AlertDialog;

importandroid.content.Context;

importandroid.os.Bundle;

importandroid.view.LayoutInflater;

importandroid.view.View;

importandroid.view.View.OnClickListener;

importandroid.widget.Button;

importandroid.widget.ImageView;

importandroid.widget.TextView;

  

publicclassLayoutInflaterDemoextendsActivityimplementsOnClickListener{

  

    privateButtonbutton;

  

    publicvoidonCreate(BundlesavedInstanceState){

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

  

        button=(Button)findViewById(R.id.button);

        button.setOnClickListener(this);

    }

  

    @Override

    publicvoidonClick(Viewv){

  

        showCustomDialog();

    }

  

    publicvoidshowCustomDialog(){

        AlertDialog.Builderbuilder;

        AlertDialogalertDialog;

        ContextmContext=LayoutInflaterDemo.this;

  

        //下面俩种方法都可以

        ////LayoutInflaterinflater=getLayoutInflater();

        LayoutInflaterinflater=(LayoutInflater)mContext

                .getSystemService(LAYOUT_INFLATER_SERVICE);

        Viewlayout=inflater.inflate(R.layout.custom_dialog,null);

        TextViewtext=(TextView)layout.findViewById(R.id.text);

        text.setText("Hello,WelcometoMrWei'sblog!

");

        ImageViewimage=(ImageView)layout.findViewById(R.id.image);

        image.setImageResource(R.drawable.icon);

        builder=newAlertDialog.Builder(mContext);

        builder.setView(layout);

        alertDialog=builder.create();

        alertDialog.show();

    }

}

5、最后执行,点击Button,将得到上述效果。

AndroidMenuInflater的使用

大家好,我们上一节讲的是LayoutInflater的使用,而这一节我将讲一下AndroidMenuInflater,顾名思义,AndroidMenuInflater是用来解析定义在layout下的布局文件,那么MenuInflater是不是用来解析定义在menu目录下的菜单布局文件呢?

恭喜你答对了!

我们传统意义上的布局定义菜单感觉比较繁琐,当我们使用MenuInflater来生成菜单,你会发现是多么的爽朗,呵呵,我今天的小Demo,是定义四个菜单,并且实现了一个菜单事件。

就是我们点击设置(Setting)菜单,进入手机设置状态!

下面看一下效果图:

下面是实现Demo的详细步骤:

一、建立一个Android工程我们命名为MenuInflaterDemo

二、在res目录下创建menu目录,并且创建options_menu.xml(我们定义的菜单)文件,代码如下:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

xmlversion="1.0"encoding="utf-8"?

>

android="

    

        android:

id="@+id/menu_add" 

        android:

title="Add"

        android:

icon="@android:

drawable/ic_menu_add"/>

    

        android:

id="@+id/menu_wallaper" 

        android:

title="Wallpaper"

        android:

icon="@android:

drawable/ic_menu_gallery"/>

    

        android:

id="@+id/menu_search" 

        android:

title="Search"

        android:

icon="@android:

drawable/ic_search_category_default"/>

    

        android:

id="@+id/menu_setting" 

        android:

title="Settings"

        android:

icon="@android:

drawable/ic_menu_preferences"/>

三、主类MenuInflaterDemo.java的编码,这里写的代码很少哦,我这里只写了第四个菜单(Settings)的响应事件。

全部代码如下:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

packagecom.android.tutor;

  

importandroid.app.Activity;

importandroid.content.Intent;

importandroid.os.Bundle;

importandroid.view.Menu;

importandroid.view.MenuInflater;

importandroid.view.MenuItem;

  

publicclassMenuInflaterDemoextendsActivity{

    @Override

    publicvoidonCreate(BundlesavedInstanceState){

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

    }

  

    @Override

    publicbooleanonCreateOptionsMenu(Menumenu){

        MenuInflaterinflater=getMenuInflater();

        inflater.inflate(R.menu.options_menu,menu);

        returntrue;

    }

  

    @Override

    publicbooleanonOptionsItemSelected(MenuItemitem){

        switch(item.getItemId()){

        caseR.id.menu_add:

  

            break;

        caseR.id.menu_wallaper:

            break;

        caseR.id.menu_search:

            break;

        caseR.id.menu_setting:

            showSettings();

            break;

        }

        returnsuper.onOptionsItemSelec

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 成人教育 > 电大

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1