android 1C 学习

本文介绍了一款生日贺卡App的设计与实现过程,重点讲解了如何使用RelativeLayout进行非线性布局,设置ImageView和TextView的属性,以及具体的XML代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

生日贺卡制作过程
1.先确定整个界面的布局来选择使用什么Layout,因为是非线性布局所以选择RelativeLayout.
2.确定有那几个标签,一个ImageView,两个TextView
3.确定ImageView的属性,高度和宽度都是match_parent,将需要使用的图片添加到drawable文件夹下,然后再使用,图片的缩放模式是
CenterCrop会调图片的比例。
4.其中的一个TextView在Layout中的位置是在左上角,由于默认位置所以不需调整,另一个则在右下角需要这两个属性调位置。
android:layout_alignParentRight=”true” android:layout_alignParentBottom=”true”
5.剩下的TextView的属性两个就一样了,调整字号,调整字体,字体颜色,以及padding空白。

//下面是生日贺卡的代码

<?xml version="1.0" encoding="utf-8"?>
<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.ydh.myfapplication.MainActivity">

    <RelativeLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent"></RelativeLayout>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/happy"
        android:scaleType="centerCrop"
        android:id="@+id/image" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Happy Birthday!"
        android:textSize="36sp"
        android:textColor="@android:color/white"
        android:padding="8dp"
        android:fontFamily="sans-serif-light" />                             

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="From yudhui"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:fontFamily="sans-serif-light"
        android:textColor="@android:color/white"
        android:padding="8dp"
        android:textSize="36sp" />
</RelativeLayout>

成品图:
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值