Android应用开发——布局管理

代码工程下载链接

一、设计目的

  1. 了解四种布局管理器的区别和各自特别的属性
  2. 掌握四种布局管理器的应用场合和用法
  3. 灵活使用四种布局文件管理器和嵌套实现各种复杂布局
  4. 掌握复用XML布局文件的方法
  5. 掌握代码控制UI界面的方法

二、软硬件环境

开发环境:Android Studio
模拟运行:Android Emulator – Nexus_5X_API_24

三、实现过程及结果

3.1 用Java代码设置全屏:打开工程的主Activity文件,在onCreate方法中执行语句super.onCreate(saveInstanceState)之前,添加语句:

requestWindowFeature(Window.FEATURE_NO_TITLE);// 隐藏标题栏
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏运营图标、点量等
super.onCreate(savedInstanceState);

3.2 完成Android应用UI的开发

3.2.1 将主布局修改为线性布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFAE4"
    android:orientation="vertical"
    >

3.2.2 在主布局中添加一个现实logo的ImageView组件

<ImageView
        android:layout_width="match_parent"
        android:layout_height="81dp"
        android:src="@mipmap/test3"/>

3.2.3 主布局中继续添加一个线性布局,该布局分为两列,分别放置头像和表格布局,表格布局也分为两行,放置用户名和密码

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="90dp"
            android:src="@mipmap/ic_launcher"/>
        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TableRow>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="账号:"/>
                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/user"/>
            </TableRow>
            <TableRow>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:minWidth="300px"
                    android:text="密码:"/>
                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/password"
                    android:inputType="textPassword"/>
            </TableRow>
        </TableLayout>
    </LinearLayout>

3.2.4 在主布局中继续添加一个登陆按钮

<Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="登录"
        android:onClick="login"/>

3.2.5 在主布局中继续添加三个已选中的复选框,分别为记住密码,自动登陆和接收产品推广

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="记住密码"/>
    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="自动登录"/>
    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="接收推广"/>

3.2.6 在主布局中继续添加一个布局管理器,该布局管理中防止忘记密码和注册账号两个按钮

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:text="忘记密码"
            android:onClick="forgetpassword"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:text="注册账号"
            android:onClick="register"/>
    </FrameLayout>

3.2.7 在主布局中继续添加一个布局管理器,该布局管理器放置进度条和表示加载中的文本框

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="63dp"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/loading"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <ProgressBar
            style="?android:attr/progressBarStyleSmall"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_marginBottom="10dp" />

</LinearLayout>

3.3 在主Activity文件中添加用于登陆的login方法,用于处理忘记密码的forgetPassword方法,用于打开注册界面的register方法

public void login(View view){
        if( true ){
            StringBuilder sb = new StringBuilder();

            sb.append("登录成功!"+"\n");
            sb.append("用户名:" + userName.getText().toString()+"\n");
            sb.append("密码:" + password.getText().toString()+"\n");

            Toast.makeText(this, sb.toString(), Toast.LENGTH_LONG).show();

            Intent intent = new Intent();   //登录到ResultActivity页面
            intent.setClass(this, ResultActivity.class);
            intent.putExtra("info", sb.toString());
            this.startActivity(intent);
        }
    }

    //打开忘记密码界面
    public void forgetpassword(View view){
        StringBuilder sb = new StringBuilder();

        Intent intent = new Intent();
        intent.setClass(this, ForgetPassActivity.class);
        intent.putExtra("info", sb.toString());
        this.startActivity(intent);
    }

    //打开注册界面
    public void register(View view){
        StringBuilder sb = new StringBuilder();

        Intent intent = new Intent();
        intent.setClass(this, RegisterActivity.class);
        intent.putExtra("info", sb.toString());
        this.startActivity(intent);
    }

3.4 界面布局后界面如图:

这里写图片描述

3.5 输入内容以及点击登陆后界面如图:

这里写图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 新闻app是一款基于Android平台的小型项目应用程序,它用于展示各类新闻内容,为用户提供便捷的阅读体验。该项目的源码包含了应用程序的基本框架和功能实现,方便开发者进行二次开发和定制。 新闻app的源码要包含以下几个方面的内容: 1. 用户界面设计:源码包含了新闻app的界面布局和样式,开发者可以根据自己的需要进行修改和美化。用户界面通常包括新闻列表、新闻详情页、分类标签等,开发者可以自由设计并添加其他功能模块。 2. 数据获取与展示:源码实现了与服务器进行数据交互的功能,通过网络请求获取新闻数据,并在界面上展示出来。开发者可以根据需要修改数据请求接口和解析方式,实现与自己的服务器交互。 3. 新闻分类与搜索:源码提供了新闻分类和搜索功能的实现,用户可以根据自己的兴趣和需求选择不同的新闻分类进行浏览,也可以通过搜索关键词进行精确定位。 4. 用户交互与分享:源码包含了用户的登录注册功能和新闻内容的分享功能,用户可以通过登录账号进行个性化设置和收藏喜欢的新闻内容,也可以将新闻分享到社交媒体上与他人交流。 总之,新闻app源码是一个基础框架,开发者可以在此基础上进行二次开发和定制,根据自己的需求添加功能模块和美化界面,实现自己独特的新闻应用。 ### 回答2: Android新闻App是一个基于Android平台开发的小型项目,它的要功能是提供最新的新闻内容给用户,并且用户可以进行浏览、搜索和分享等操作。下面是这个项目的一些关键特点和所需的源码组成部分: 1. 特点: - 用户界面友好,交互性强,提供舒适的浏览体验; - 支持实时更新,提供最新的新闻内容; - 具备搜索功能,方便用户查找感兴趣的新闻; - 支持新闻分享功能,方便用户将新闻分享给朋友; - 具备图文混排的能力,可以展示新闻的文字和图片。 2. 源码组成部分: - 界面布局代码:定义了App的整体布局结构,包括顶部导航栏、底部工具栏和新闻显示区域等。 - 数据源代码:负责获取新闻数据,可以通过API接口获取最新的新闻内容,也可以从本地数据库获取已缓存的新闻数据。 - 新闻列表适配器代码:用于将新闻数据展示在界面上,包括标题、描述和图片等。 - 新闻详情界面代码:用于显示单篇新闻的详细内容,包括标题、正文和相关图片等。 - 搜索功能代码:实现了按关键字搜索新闻的功能,可以在已有的新闻数据进行筛选。 - 分享功能代码:集成了社交媒体的分享SDK,方便用户将新闻内容分享给朋友。 - 图片加载和缓存代码:处理了新闻的图片加载和本地缓存,提高了图片加载速度和用户体验。 通过以上的源码组成部分,可以完成一个基本的新闻App,用户可以在界面上浏览最新的新闻内容,进行搜索和分享操作。这个小项目可以帮助开发者理解Android开发框架和开发方式,提高编码能力和UI设计能力。 ### 回答3: 新闻app是基于Android平台开发的一个小型应用程序,可以提供用户各种最新的新闻资讯。以下是关于这个项目的源码介绍。 该项目源码要由Java语言编写,使用了Android Studio作为开发工具。代码结构清晰,包含了要的几个模块。 1. 用户界面模块:这个模块负责显示新闻列表和新闻详情等信息,要包含布局文件和相应的逻辑代码。列表界面使用RecyclerView控件展示新闻列表,详情界面使用WebView展示新闻内容。 2. 网络请求模块:这个模块负责与后台服务器进行数据交互,使用了Android的HttpURLConnection类来发送请求和接收响应。请求参数可以根据实际需要进行修改,例如可以根据新闻类别进行请求。 3. 数据解析模块:这个模块负责解析从服务器返回的JSON格式的数据,转换成Java对象供应用程序使用。可以使用Android提供的JSON解析库,如Gson。 4. 数据存储模块:这个模块负责缓存新闻数据,以提高应用程序的响应速度。可以使用SharedPreferences或SQLite数据库来存储新闻数据。同时也可以使用图片缓存库,如Glide或Picasso来缓存新闻图片。 5. 用户交互模块:这个模块负责处理用户的交互行为,例如点击新闻列表项跳转到新闻详情界面,下拉刷新获取最新数据等。可以使用Android提供的相关控件和事件监听器来实现用户交互。 除了以上几个要的模块,还可以根据需要添加其他功能,例如搜索栏、分享按钮等。 总体来说,这个新闻app的源码提供了一个完整的开发框架,初学者可以通过阅读和理解源码来学习Android应用程序的开发流程和一些常用技术。同时,也可以根据实际需求进行二次开发,添加新的功能和改进用户体验。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值