上一个星期做的了,一直没有写,很悲伤啊,因为不太会。老师给了一个看了看,发现挺简单的还,并不难。
市面上的大多数的Android应用如新浪微博、网易新闻都是网络应用,都需要与服务器进行通信。下面通过这一个案例“网络图片浏览器”像大家演示手机端与服务器进行通信的过程。如下:
一、创建程序
创建一个“网络图片浏览器”应用程序,将包名改为cn.edu.bzu。设计用户交互页面。
"网络图片浏览器”对应的布局文件如下(activity_main.xml):
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/iv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<EditText
android:id="@+id/et_path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="请输入图片路径"
android:text="http://b.hiphotos.baidu.com/image/w%3D310/sign=a439f5b24510b912bfc1f0fff3fdfcb5/83025aafa40f4bfb92c52c5d014f78f0f73618a5.jpg"
android:maxLines="1
Android网络图片浏览器教程

本文介绍了如何创建一个简单的Android应用——网络图片浏览器。通过修改包名为cn.edu.bzu,设计用户界面并编写交互代码,利用HttpURLConnection请求网络图片。文章详细讲解了布局文件中的关键属性android:layout_weight,并在MainActivity中实现网络请求。最后,添加必要的网络权限,让应用能够成功从服务器获取并显示图片。
最低0.47元/天 解锁文章
2772

被折叠的 条评论
为什么被折叠?



