/minip.jpg

技术博客分享

1鸿蒙开发工具DevEco-Studio的下载和安装

/weixin_miniapp.png

1、鸿蒙开发工具DevEco Studio的下载和安装

一、DevEco Studio概述

1、简介

HUAWEI DevEco Studio(获取工具请单击链接下载,以下简称DevEco Studio)是基于IntelliJ IDEA Community开源版本打造,为运行在HarmonyOS和OpenHarmony系统上的应用和服务(以下简称应用/服务)提供一站式的开发平台。

Android移动开发之网络图片浏览器案例详细实现方法

/weixin_miniapp.png

Android移动开发之网络图片浏览器案例详细实现方法

网络图片浏览器的实现效果:

https://i-blog.csdnimg.cn/blog_migrate/688065d56ca040366049ca117da22f00.png#pic_center

实现步骤:

① 用户交互界面的设计与实现

② 界面逻辑代码的设计与实现

③ 添加访问网络权限

  1. 我们启动android studio开发工具。
  2. 创建一个新项目,选择Empty Activity空模板,点击下一步。
  3. 项目名字命名为ImageView,点击finish完成,等待项目相关配置自动加载完成。
  4. 准备工作,我们案例中用到了背景图片bg.jpg,我们先将图片素材放到res-drawable文件夹中。
  5. 接下来我们开始用户交互界面的设计与实现,在res-layout文件夹中打开Activity_main文件,我们整个界面采用相对布局Relaticelayout来设计其中的控件。我们修改一下相关参数:
<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"
    android:background="@drawable/bg"
    tools:context=".MainActivity">
</RelativeLayout>
  1. 接下来添加一个线型布局,并在其中添加文本编辑控件和按钮控件。
<LinearLayout
        android:id="@+id/ll_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_marginTop="10dp"
        android:orientation="horizontal">
        <EditText
            android:id="@+id/et_path"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginRight="3dp"
            android:layout_weight="1"
            android:background="#EBEBEB"
            android:hint="请输入图片路径"
            android:inputType="textUri"
            android:paddingLeft="3dp"
            android:textColor="#696969"
            android:textSize="20sp" />
        <Button
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="4"
            android:background="#EBEBEB"
            android:onClick="click"
            android:text="浏览"
            android:textColor="#696969"
            android:textSize="20sp" />
    </LinearLayout>
  1. 在线型布局下面添加一个视图控件,用来显示获取的网络图像。
<ImageView
        android:id="@+id/iv_pic"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/ll_text"
        android:scaleType="centerCrop" />

到目前为止我们的界面布局代码就编写完成。