Android Studio入门级UI界面设计(图文+解析)

本文以图片加上解析,希望小白可以理解通透

下面配上本次试验UI界面

在这里插入图片描述

- 1.首先设置成线性布局,添加orientation属性,设置成垂直
android:orientation="vertical"
- 设置padding为8dp(Padding 为内边框,指该控件内部内容,如文本/图片距离该控件的边距)
android:padding="8dp"
- 2.建立一个testview写标题
<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="账号登录"
    android:textSize="40dp"/>

标题字体大小 40dp(android:textSize=“40dp”)

-3. 建立两个editview,输入框

要让Edittext单行显示

android:maxLines="1"

限制显示文本长度,超出不显示

android:maxLength="10"

文本为空时候显示的文本

android:hint="请输入你的账号(最多十个字符)"

文本过长时,省略号显示在结尾

android:ellipsize="end"

距离顶部的距离

android:layout_marginTop="80dp"
-4. 建立登录按钮,button

android:layout_gravity是用来设置该view相对与父view 的位置.比如一个button 在linearlayout里,你想把该button放在linearlayout里靠左、靠右等位置就可以通过该属性设置

android:layout_gravity="center"
-5. 添加一个相对布局RelativeLayout,在里面建立CheckBox控件
<CheckBox
    android:id="@+id/cb_rm"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
       android:text="记住密码"
       android:textSize="18dp"
        />
-6.再在里面建立一个testview(忘记密码)
<TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="忘记密码"
            android:textColor="#9E2222"
            android:layout_centerVertical="true"
            android:textSize="18dp" />

将控件的右边缘和父控件的右边缘对齐

android:layout_alignParentRight="true"

将控件置于垂直方向的中心位置

android:layout_centerVertical="true"

-试验成功,代码如下

<?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:padding="8dp"
    android:background="#F8F7F7">
    <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="账号登录"
    android:textSize="40dp"/>
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入你的账号(最多十个字符)"
        android:id="@+id/et_username"
        android:layout_marginTop="80dp"
        android:textColor="#9ACCA7"
        android:maxLines="1"
        android:ellipsize="end"
        android:maxLength="10"/>
    <EditText
        android:id="@+id/et_pw"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入你的密码"
        android:layout_marginTop="10dp"
        android:textColor="#DAC3E0"
        android:maxLines="1"
        android:ellipsize="end"/>
    <Button
        android:layout_marginTop="25dp"
        android:layout_width="300dp"
        android:layout_height="60dp"
        android:text="登录"
        android:textSize="25dp"
        android:layout_gravity="center"/>
    <RelativeLayout
        android:layout_marginTop="50dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    <CheckBox
        android:id="@+id/cb_rm"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="记住密码"
        android:textSize="18dp"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="忘记密码"
            android:textColor="#9E2222"
            android:layout_centerVertical="true"
            android:textSize="18dp" />
    </RelativeLayout>
</LinearLayout>

如果是新入门的同学可以参考之前的文章哦

Android Studio 安装配置完整教程
Android Studio入门级教程
Android 布局 天气预报demo

  • 12
    点赞
  • 99
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
Android Studio中进行页面设计时,可以使用不同的布局和属性来实现所需的效果。首先,你需要了解一些基本的布局和属性,以便正确地设计页面。 一个常用的布局是RelativeLayout,你可以在其中添加各种视图,并使用android:layout_alignParent属性来指定它们相对于父视图的位置。例如,你可以使用以下属性来将一个CheckBox控件放在RelativeLayout中,并设置其相对于父视图的位置: ``` <CheckBox android:id="@id/cb_rm" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="记住密码" android:textSize="18dp" android:layout_alignParentLeft="true" android:layout_centerVertical="true" /> ``` 你还可以在RelativeLayout中添加其他视图,例如一个TextView,你可以使用android:layout_alignParentRight属性将其放在右侧: ``` <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="忘记密码" android:textColor="#9E2222" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:textSize="18dp" /> ``` 还可以使用LinearLayout布局来设置视图的位置,使用android:layout_gravity属性来指定视图相对于父视图的位置。例如,你可以使用以下属性将一个Button放在LinearLayout的右侧: ``` <Button android:id="@+id/login_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登录" android:layout_gravity="right" /> ``` 另外,还可以使用android:layout_marginTop属性来指定视图与顶部的距离。例如,你可以使用以下属性将一个视图与顶部保持80dp的距离: ``` android:layout_marginTop="80dp" ``` 通过使用这些布局和属性,你可以根据需要设计Android Studio页面。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Android Studio入门级UI界面设计图文解析)](https://blog.csdn.net/m0_46350041/article/details/105031143)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值