把大象放冰箱

把大象放冰箱统共分三步:

轻轻的打开冰箱门
把大象赶进去,当然手也拿不动
大象进去后就 把冰箱门关上

创建一个Android应用程序也分三步,但首先你得学习绘画,把用户界面作出来,通过绘画可以自动生成代码。所以可以说从绘画到编码只需三步!

Three easy steps
学过三视图啦

当你有了剧本你才能去拍摄一幅幅影像,但程序设计却恰恰相反,从已有设计原型开始,从一帧帧绘制原型到编写代码。
把资源文件,如背景图片,放置在指定的资源文件夹内。

The Drawable Folder
Background Image

通过ImageView的src属性赋值就可以选择这幅背景图片了。
是的,项目文件中已经有了背景图片文件了。

项目文件
<TextView
    android:text="Happy Birthday YOUYOU"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
<TextView
    android:text="From Simtech2win"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
<ImageView
    android:src="@drawable/androidparty"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />

加入上面的代码,可以看到预览如下:

Select Views

第一步:选择大象

冰箱里放哪只大象?布局中都包含哪些视图?是,首先选择视图。
两个TextView,一幅背景图片。哇,这不是放一只大象,是把三只小象都放里面。

2 TextViews                    //不同位置的两段文字
1 ImageViews                   //一幅活动的背景图片
打开冰箱门
<                             打开了
把大象赶进去
2 TextViews                    //谁家的两只小象
1 ImageViews                   //谁家的一只小象
关上冰箱门
/>                            关上了

第二步:决定位置

三只小象各置于什么位置?相互之间什么关系,会不会一只象骑在另一只象身上?还是一只挨着一只依次排开?还是彼此之间相对或绝对保持一定距离?靠边站?还是挤到角落里?
给张图说明:

自己的位置不知道吗?
        android:layout_alignParentRight = "true"
        android:layout_alignParentBottom = "true"
From Simtech2win布置到右下角

第三步:鼻子插大葱,妆相

英文叫做Style the views,文本、按钮、图片反正不管是什么,都得给出一个特殊的形象,妆饰是必须的,各种妆!
文本大一点或者小一点?字体?颜色?

android:textSize="48sp"
android:fontFamily="sans-serif-light"
android:textColor="@android:color/white"

图片的伸缩方式

android:scaleType="centerCrop"
或者
android:scaleType="center"
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.dell.happybirthday.MainActivity">
    <ImageView
        android:id="@+id/photo_image_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="center"
        android:src="@drawable/fish" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Happy Birthday YouYou!"
        android:fontFamily="sans-serif-light"
        android:textColor="@android:color/white"
        android:layout_margin="5dp"
        android:textSize="36sp"/>
        android:
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="From Simtech2win"
        android:textSize="36sp"
        android:padding="5dp"
        android:fontFamily="sans-serif-light"
        android:textColor="@android:color/white"
        android:layout_alignParentRight = "true"
        android:layout_alignParentBottom = "true"/>
    </RelativeLayout>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,268评论 25 709
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,668评论 4 61
  • 雨后夜行 文/change ...
    change_mds阅读 2,224评论 0 6
  • 初中时,男孩子都爱打架。同学有什么恩怨,打一架,有可能一笑泯恩仇,成为兄弟。男生之间的情谊总是来的突然。我这里要写...
    瑾夏之絮阅读 1,769评论 0 0
  • 很多人觉得学好英语很难,对于英文原版书更是没有勇气尝试,但其实有很多英文原版书高中生甚至初中生都可以轻松地阅读。今...
    荐书少女阅读 15,783评论 1 8

友情链接更多精彩内容