app开发历程——android手机显示服务器端图片思路

时间:2022-06-16 15:53:20

以前自己都不知道怎么去显示服务器端的图片,还好在apkbus论坛上找到一个特别简单的例子。虽然一天天忙忙碌碌,但是自己内心其实有一种想逃的心里,说不定哪天就会冒出来。

1、首先服务器端图片

app开发历程——android手机显示服务器端图片思路

这里的ImageServlet.java,没有做相关处理

这里启动tomcat,这时在浏览器中输入http://localhost:8080/ReadImage1/image/a.jpg

这时应该能看到这张图片。

2、android程序

布局文件:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="网路图片地址" /> <EditText
android:id="@+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="http://192.168.0.121:8081/ReadImage1/image/" /> <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="显示" /> <WebView
android:id="@+id/webView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> </LinearLayout>

相关后台代码

package com.haofs.demo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText; public class ImageClientActivity extends Activity implements OnClickListener {
private Button button;
private EditText editText;
private WebView webView; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button) findViewById(R.id.button1);
editText = (EditText) findViewById(R.id.editText);
webView = (WebView) findViewById(R.id.webView); button.setOnClickListener(this);
} @Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
webView.loadUrl(editText.getText().toString());
}
}

本文来自:

从Android客户端加载服务端的图片
http://www.apkbus.com/forum.php?mod=viewthread&tid=97293
(出处: Android开发论坛 - 安卓开发论坛 - Android开发 - 安卓论坛 - 移动互联网门户)

生活的一步一步,思想的一寸一寸,无时无刻......