Android布局管理器-使用LinearLayout实现简单的登录窗口布局

场景

Android布局管理器-从实例入手学习相对布局管理器的使用:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/103838924

线性布局LinearLayout,分为水平和垂直线性布局。

实现效果如下

 

注:

博客:
https://blog.csdn.net/badao_liumang_qizhi
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。

实现

将activity修改为LinearLayout布局

 

并且通过   

android:orientation="vertical"

设置其为竖直线型布局。

然后添加两个输入框分别为用户名和密码

通过

android:hint="请输入账户"

设置输入框提示文本

通过

android:drawableLeft="@drawable/account"

设置输入框左边的图片

这里的图片是放在res下的drawable目录下

 

然后添加一个按钮,设置其颜色。

完整示例代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".LinearLayoutActivity">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="20dp"
        android:hint="请输入账户"
        android:drawableLeft="@drawable/account"
        />

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="20dp"
        android:hint="请输入密码"
        android:drawableLeft="@drawable/pass"
        />
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="登录"
        android:textColor="#FFFFFF"
        android:background="#FF009688"
        />

</LinearLayout>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
好的,我可以帮您创建一个用户登录界面的Activity,并设置相应的布局。 首先,您需要在Android Studio中创建一个新的Activity。可以按照以下步骤进行操作: 1. 在Android Studio中打开您的项目,选择要创建Activity的模块。 2. 在Project视图中,右键单击app文件夹,选择New > Activity > Empty Activity。 3. 在弹出的窗口中,输入Activity的名称,比如LoginActivity,然后点击Finish。 现在,您已经创建了一个新的Activity。接下来,我们可以为它设置布局。 在res/layout文件夹下,创建一个名为activity_login.xml的布局文件。可以按照以下代码进行编写: ```xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="16dp"> <EditText android:id="@+id/editTextEmail" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Email" /> <EditText android:id="@+id/editTextPassword" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Password" android:inputType="textPassword" /> <Button android:id="@+id/buttonLogin" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Login" /> </LinearLayout> ``` 这个布局文件中包含了三个控件:一个EditText用于输入Email,一个EditText用于输入密码,以及一个Button用于登录。您可以根据需要进行修改。 最后,在LoginActivity中,可以使用setContentView方法将该布局文件设置为Activity的视图。可以按照以下代码进行编写: ```java public class LoginActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); } } ``` 现在,您已经成功创建了一个用户登录界面的Activity,并设置了相应的布局

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

霸道流氓气质

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值