`

Android ListView从网络获取图片及文字显示

阅读更多
如何从网络获取图片以及文本来显示。事实上,一般是先获取Josn或sml数据,然后解释显示。我们先从网上获取xml,然后对其进行解析,最后显示在ListView上。具体步骤:
•客户端发出请求,获取xml
•客户端异步解析xml
•ListView将解析完的数据显示

      一、Android客户端


(1)xml布局文件

        mainxml,就是一个ListView。
<?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">
	
    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:divider="#b5b5b5"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/list_selector" />

</LinearLayout>


ListView的每一行的布局,list_raw.xml,看一下结构图:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/list_selector"
    android:orientation="horizontal"
    android:padding="5dip" >

	<!--  ListView最左边的缩略图 -->
	<LinearLayout android:id="@+id/thumbnail" 
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:padding="3dip"		
        android:layout_alignParentLeft="true"
        android:background="@drawable/image_bg" 
	    android:layout_marginRight="5dip">
        
		<ImageView     
	        android:id="@+id/list_image"   
	        android:layout_width="50dip"
	        android:layout_height="50dip"
	        android:src="@drawable/rihanna"/>
        
	</LinearLayout>
    
	<!-- 歌曲名-->
    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/thumbnail"
        android:layout_toRightOf="@+id/thumbnail"
        android:text="Rihanna Love the way lie"
        android:textColor="#040404"
        android:typeface="sans" 
        android:textSize="15dip"
        android:textStyle="bold"/>

	<!-- 歌手名 -->
    <TextView
        android:id="@+id/artist"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/title"
        android:textColor="#343434"
        android:textSize="10dip"
        android:layout_marginTop="1dip"
        android:layout_toRightOf="@+id/thumbnail"
        android:text="Just gona stand there and ..." />

	<!-- 歌曲播放时间 -->
    <TextView
        android:id="@+id/duration"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@id/title"
        android:gravity="right"
        android:text="5:45"
        android:layout_marginRight="5dip"
        android:textSize="10dip"
        android:textColor="#10bcc9"
        android:textStyle="bold"/>
      
     <!-- 进入播放 -->    
     <ImageView android:layout_width="wrap_content"
     	android:layout_height="wrap_content"
     	android:src="@drawable/arrow"
     	android:layout_alignParentRight="true"
     	android:layout_centerVertical="true"/>

</RelativeLayout>


另外我们打算使用几个特效,一个是当点击列表项目的时候,项目背景色改变,其实就是一个selector;另一个就是用shape美化视觉效果,具体看xml代码:

      1.list_selector.xml     
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Selector style for listrow -->
<item 
 android:state_selected="false"
    android:state_pressed="false" 
    android:drawable="@drawable/gradient_bg" />
<item android:state_pressed="true" 
    android:drawable="@drawable/gradient_bg_hover" />
<item android:state_selected="true"
 android:state_pressed="false" 
    android:drawable="@drawable/gradient_bg_hover" />
</selector>




2.gradient_bg.xml,是默认背景梯度风格 
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
  <!--  Gradient Bg for listrow -->
  <gradient
      android:startColor="#f1f1f2"
      android:centerColor="#e7e7e8"
      android:endColor="#cfcfcf"
      android:angle="270" />
</shape>

3.gradient_bg_hover.xml 梯度风格在悬停状态
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
  <!-- Gradient BgColor for listrow Selected -->
  <gradient
      android:startColor="#18d7e5"
      android:centerColor="#16cedb"
      android:endColor="#09adb9"
      android:angle="270" />
  
</shape>

4.image_bg.xml 在图片周围的白色边条
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
      <shape 
        android:shape="rectangle">
            <stroke android:width="1dp" android:color="#dbdbdc" />
            <solid android:color="#FFFFFF" />
        </shape>
   </item>
</layer-list>


以上效果基本上都用到了shape,对此不了解的可以去查看相关资料。上面就是全部的xml布局文件,下面将开始写代码。



   (2)主要代码


            代码部分主要涉及到一下几个功能,重写ListView的适配器(BaseAdapter),从网络获取图片,图片缓存的处理,xml的解析。

            ①重写ListView的适配器,这部分可以参考上一篇文章,LazyAdapter.java     
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class LazyAdapter extends BaseAdapter {
    
    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; //用来下载图片的类,后面有介绍
    
    public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.list_row, null);

        TextView title = (TextView)vi.findViewById(R.id.title); // 标题
        TextView artist = (TextView)vi.findViewById(R.id.artist); // 歌手名
        TextView duration = (TextView)vi.findViewById(R.id.duration); // 时长
        ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // 缩略图
        
        HashMap<String, String> song = new HashMap<String, String>();
        song = data.get(position);
        
        // 设置ListView的相关值
        title.setText(song.get(CustomizedListView.KEY_TITLE));
        artist.setText(song.get(CustomizedListView.KEY_ARTIST));
        duration.setText(song.get(CustomizedListView.KEY_DURATION));
        imageLoader.DisplayImage(song.get(CustomizedListView.KEY_THUMB_URL), thumb_image);
        return vi;
  <em>  }
}</em>


②网络获取图片的类,ImageLoader.java:
import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.io.FileOutputStream; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.net.HttpURLConnection; 
import java.net.URL; 
import java.util.Collections; 
import java.util.Map; 
import java.util.WeakHashMap; 
import java.util.concurrent.ExecutorService; 
import java.util.concurrent.Executors;  
import android.app.Activity; 
import android.content.Context; 
import android.graphics.Bitmap; 
import android.graphics.BitmapFactory; 
import android.widget.ImageView; 
  
public class ImageLoader { 
  
    MemoryCache memoryCache=new MemoryCache(); 
    FileCache fileCache; 
    private Map<ImageView, String> imageViews=Collections.synchronizedMap(new WeakHashMap<ImageView, String>()); 
    ExecutorService executorService;  
  
    public ImageLoader(Context context){ 
        fileCache=new FileCache(context); 
        executorService=Executors.newFixedThreadPool(5); 
    } 
  
    final int stub_id = R.drawable.no_image; 
    public void DisplayImage(String url, ImageView imageView) 
    { 
        imageViews.put(imageView, url); 
        Bitmap bitmap=memoryCache.get(url); 
        if(bitmap!=null) 
            imageView.setImageBitmap(bitmap); 
        else
        { 
            queuePhoto(url, imageView); 
            imageView.setImageResource(stub_id); 
        } 
    } 
  
    private void queuePhoto(String url, ImageView imageView) 
    { 
        PhotoToLoad p=new PhotoToLoad(url, imageView); 
        executorService.submit(new PhotosLoader(p)); 
    } 
  
    private Bitmap getBitmap(String url) 
    { 
        File f=fileCache.getFile(url); 
  
        //从sd卡
        Bitmap b = decodeFile(f); 
        if(b!=null) 
            return b; 
  
        //从网络
        try { 
            Bitmap bitmap=null; 
            URL imageUrl = new URL(url); 
            HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection(); 
            conn.setConnectTimeout(30000); 
            conn.setReadTimeout(30000); 
            conn.setInstanceFollowRedirects(true); 
            InputStream is=conn.getInputStream(); 
            OutputStream os = new FileOutputStream(f); 
            Utils.CopyStream(is, os); 
            os.close(); 
            bitmap = decodeFile(f); 
            return bitmap; 
        } catch (Exception ex){ 
           ex.printStackTrace(); 
           return null; 
        } 
    } 
  
    //解码图像用来减少内存消耗
    private Bitmap decodeFile(File f){ 
        try { 
            //解码图像大小
            BitmapFactory.Options o = new BitmapFactory.Options(); 
            o.inJustDecodeBounds = true; 
            BitmapFactory.decodeStream(new FileInputStream(f),null,o); 
  
            //找到正确的刻度值,它应该是2的幂。
            final int REQUIRED_SIZE=70; 
            int width_tmp=o.outWidth, height_tmp=o.outHeight; 
            int scale=1; 
            while(true){ 
                if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE) 
                    break; 
                width_tmp/=2; 
                height_tmp/=2; 
                scale*=2; 
            } 
  
            BitmapFactory.Options o2 = new BitmapFactory.Options(); 
            o2.inSampleSize=scale; 
            return BitmapFactory.decodeStream(new FileInputStream(f), null, o2); 
        } catch (FileNotFoundException e) {} 
        return null; 
    } 
  
    /任务队列
    private class PhotoToLoad 
    { 
        public String url; 
        public ImageView imageView; 
        public PhotoToLoad(String u, ImageView i){ 
            url=u; 
            imageView=i; 
        } 
    } 
  
    class PhotosLoader implements Runnable { 
        PhotoToLoad photoToLoad; 
        PhotosLoader(PhotoToLoad photoToLoad){ 
            this.photoToLoad=photoToLoad; 
        } 
  
        @Override
        public void run() { 
            if(imageViewReused(photoToLoad)) 
                return; 
            Bitmap bmp=getBitmap(photoToLoad.url); 
            memoryCache.put(photoToLoad.url, bmp); 
            if(imageViewReused(photoToLoad)) 
                return; 
            BitmapDisplayer bd=new BitmapDisplayer(bmp, photoToLoad); 
            Activity a=(Activity)photoToLoad.imageView.getContext(); 
            a.runOnUiThread(bd); 
        } 
    } 
  
    boolean imageViewReused(PhotoToLoad photoToLoad){ 
        String tag=imageViews.get(photoToLoad.imageView); 
        if(tag==null || !tag.equals(photoToLoad.url)) 
            return true; 
        return false; 
    } 
  
    //用于显示位图在UI线程
    class BitmapDisplayer implements Runnable 
    { 
        Bitmap bitmap; 
        PhotoToLoad photoToLoad; 
        public BitmapDisplayer(Bitmap b, PhotoToLoad p){bitmap=b;photoToLoad=p;} 
        public void run() 
        { 
            if(imageViewReused(photoToLoad)) 
                return; 
            if(bitmap!=null) 
                photoToLoad.imageView.setImageBitmap(bitmap); 
            else
                photoToLoad.imageView.setImageResource(stub_id); 
        } 
    } 
  
    public void clearCache() { 
        memoryCache.clear(); 
        fileCache.clear(); 
    } 
  
} 


③xml解析,xml的解析有很多方法,这里采用进行dom方式的xml解析。
import java.io.IOException; 
import java.io.StringReader; 
import java.io.UnsupportedEncodingException;   
import javax.xml.parsers.DocumentBuilder; 
import javax.xml.parsers.DocumentBuilderFactory; 
import javax.xml.parsers.ParserConfigurationException;   
import org.apache.http.HttpEntity; 
import org.apache.http.HttpResponse; 
import org.apache.http.client.ClientProtocolException; 
import org.apache.http.client.methods.HttpPost; 
import org.apache.http.impl.client.DefaultHttpClient; 
import org.apache.http.util.EntityUtils; 
import org.w3c.dom.Document; 
import org.w3c.dom.Element; 
import org.w3c.dom.Node; 
import org.w3c.dom.NodeList; 
import org.xml.sax.InputSource; 
import org.xml.sax.SAXException;  
import android.util.Log; 
  
public class XMLParser { 
  
    // 构造方法
    public XMLParser() { 
  
    } 
  
    /** 
     * 从URL获取XML使HTTP请求
     * @param url string 
     * */
    public String getXmlFromUrl(String url) { 
        String xml = null; 
  
        try { 
            // defaultHttpClient 
            DefaultHttpClient httpClient = new DefaultHttpClient(); 
            HttpPost httpPost = new HttpPost(url); 
  
            HttpResponse httpResponse = httpClient.execute(httpPost); 
            HttpEntity httpEntity = httpResponse.getEntity(); 
            xml = EntityUtils.toString(httpEntity); 
  
        } catch (UnsupportedEncodingException e) { 
            e.printStackTrace(); 
        } catch (ClientProtocolException e) { 
            e.printStackTrace(); 
        } catch (IOException e) { 
            e.printStackTrace(); 
        } 
        return xml; 
    } 
  
    /** 
     * 获取XML DOM元素
     * @param XML string 
     * */
    public Document getDomElement(String xml){ 
        Document doc = null; 
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
        try { 
  
            DocumentBuilder db = dbf.newDocumentBuilder(); 
  
            InputSource is = new InputSource(); 
                is.setCharacterStream(new StringReader(xml)); 
                doc = db.parse(is);  
  
            } catch (ParserConfigurationException e) { 
                Log.e("Error: ", e.getMessage()); 
                return null; 
            } catch (SAXException e) { 
                Log.e("Error: ", e.getMessage()); 
                return null; 
            } catch (IOException e) { 
                Log.e("Error: ", e.getMessage()); 
                return null; 
            } 
  
            return doc; 
    } 
  
    /** 获取节点值
      * @param elem element 
      */
     public final String getElementValue( Node elem ) { 
         Node child; 
         if( elem != null){ 
             if (elem.hasChildNodes()){ 
                 for( child = elem.getFirstChild(); child != null; child = child.getNextSibling() ){ 
                     if( child.getNodeType() == Node.TEXT_NODE  ){ 
                         return child.getNodeValue(); 
                     } 
                 } 
             } 
         } 
         return ""; 
     } 
  
     /** 
      * 获取节点值
      * @param Element node 
      * @param key string 
      * */
     public String getValue(Element item, String str) { 
            NodeList n = item.getElementsByTagName(str); 
            return this.getElementValue(n.item(0)); 
        } 
}


④程序缓存的处理,主要是内存缓存+文件缓存。内存缓存中网上很多是采用SoftReference来防止堆溢出:

     MemoryCache.java:
import java.lang.ref.SoftReference;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import android.graphics.Bitmap;

public class MemoryCache {
    private Map<String, SoftReference<Bitmap>> cache=Collections.synchronizedMap(new HashMap<String, SoftReference<Bitmap>>());//软引用
    
    public Bitmap get(String id){
        if(!cache.containsKey(id))
            return null;
        SoftReference<Bitmap> ref=cache.get(id);
        return ref.get();
    }
    
    public void put(String id, Bitmap bitmap){
        cache.put(id, new SoftReference<Bitmap>(bitmap));
    }

    public void clear() {
        cache.clear();
    }
}


FileCache.java
import java.io.File;
import android.content.Context;

public class FileCache {
    
    private File cacheDir;
    
    public FileCache(Context context){
        //找一个用来缓存图片的路径
        if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
            cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"LazyList");
        else
            cacheDir=context.getCacheDir();
        if(!cacheDir.exists())
            cacheDir.mkdirs();
    }
    
    public File getFile(String url){
        
        String filename=String.valueOf(url.hashCode());
        File f = new File(cacheDir, filename);
        return f;
        
    }
    
    public void clear(){
        File[] files=cacheDir.listFiles();
        if(files==null)
            return;
        for(File f:files)
            f.delete();
    }

}

⑤还有一个读取流的工具类,Utils.java:
import java.io.InputStream;
import java.io.OutputStream;


public class Utils {
&nbsp; &nbsp; public static void CopyStream(InputStream is, OutputStream os)
&nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; final int buffer_size=1024;
&nbsp; &nbsp; &nbsp; &nbsp; try
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byte[] bytes=new byte[buffer_size];
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(;;)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int count=is.read(bytes, 0, buffer_size);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(count==-1)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; os.write(bytes, 0, count);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; is.close();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; os.close();
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; catch(Exception ex){}
&nbsp; &nbsp; }
}

还可以像下面这样表达,方法是一样的,就是表达形式上不同:
public static byte[] readStream(InputStream inStream) throws Exception{

ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = -1;
while( (len=inStream.read(buffer)) != -1){
outSteam.write(buffer, 0, len);

}
outSteam.close();
inStream.close();
return outSteam.toByteArray();

}
}


最后就是主Activity的代码了,

package com.example.androidhive;

import java.util.ArrayList;
import java.util.HashMap;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class CustomizedListView extends Activity {
	// 所有的静态变量
	static final String URL = "http://api.androidhive.info/music/music.xml";//xml目的地址,打开地址看一下
	// XML 节点
	static final String KEY_SONG = "song"; // parent node
	static final String KEY_ID = "id";
	static final String KEY_TITLE = "title";
	static final String KEY_ARTIST = "artist";
	static final String KEY_DURATION = "duration";
	static final String KEY_THUMB_URL = "thumb_url";
	
	ListView list;
        LazyAdapter adapter;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		

		ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();

		XMLParser parser = new XMLParser();
		String xml = parser.getXmlFromUrl(URL); // 从网络获取xml
		Document doc = parser.getDomElement(xml); // 获取 DOM 节点
		
		NodeList nl = doc.getElementsByTagName(KEY_SONG);
		// 循环遍历所有的歌节点 <song>
		for (int i = 0; i < nl.getLength(); i++) {
			// 新建一个 HashMap
			HashMap<String, String> map = new HashMap<String, String>();
			Element e = (Element) nl.item(i);
			//每个子节点添加到HashMap关键= >值
			map.put(KEY_ID, parser.getValue(e, KEY_ID));
			map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
			map.put(KEY_ARTIST, parser.getValue(e, KEY_ARTIST));
			map.put(KEY_DURATION, parser.getValue(e, KEY_DURATION));
			map.put(KEY_THUMB_URL, parser.getValue(e, KEY_THUMB_URL));

			// HashList添加到数组列表
			songsList.add(map);
		}
		

		list=(ListView)findViewById(R.id.list);
		
		
              adapter=new LazyAdapter(this, songsList);        
              list.setAdapter(adapter);
        

        //为单一列表行添加单击事件

        list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
							
                        //这里可以自由发挥,比如播放一首歌曲等等
			}
		});		
	}	
}


最后看一下效果:

分享到:
评论

相关推荐

    listview tabhost 的各种使用

    里面有关于listview tabhost 的各种使用 还有 Android ListView从网络获取图片及文字显示

    Android-listview.zip

    Android 移动开发 Android studio新建数据库并从数据库中获取到图片,文字数据显示在Listview列表上

    android 常用资大全

    网上收集和自己总结的一些android使用资料,比较基础的知识,对全面了解一些知识很不错的 ...Android之从网络上获取图片视频.docx webview属性大全.docx 菜谱aip.docx 反编译Apk得到Java源代码总结.docx

    Android40个经典源码

    29 android 获取Gps信息的程序源码 30 android 超炫的图片浏览器 31 android 加载时闪烁点样式的启动画面 32 基于 Android 的英文电子词典 33 android 源码之英语单词记忆程序源码 34 andorid 源码北京公交线路查询...

    Android应用源码30套安卓源码合集.zip

    Android 网络视频播放器源码.rar android 获取Gps信息的程序源码.rar Android 高德地图图层效果源码.rar Android中英文电子词典源码(so easy).rar android仿开心网源代码.rar android及时通讯源码:实时对讲机.rar...

    Android移动应用开发学习笔记(listview和适配器的使用)

    2.2、优化处理:3、listview显示复杂页面(在listview的一个item中显示图片和文字)3.1、activity_main.xml文件3.2、模板item.xml文件3.3、MainActivity 类4、获取打气筒的常用的api4.1、第一种4.2、第二种4.3、第三...

    Android Studio实现一个新闻APP,功能巨多,大作业必备项目

    有文字有图片还有视频可以播放,全方位给用户带来视听娱乐享受,随时随地获取时事新闻。用作毕业设计都完全可以,用作大作业那绝对也是极佳。具体的演示可以参考我的对应博客,下载下来即可运行。 博客介绍:...

    老罗android视频开发源码和ppt经典

    6.17 ImageView从网络上获取图像 6.18 DatePicker输入日期控件的使用 6.19 时间对话框的使用 6.20 ProgressBar进度条的使用 6.21 RatingBar评分控件的使用 6.22 ScrollView垂直滚动控件的使用 6.23 ...

    android 音乐播放器

    &lt;item name="android:textColor"&gt;@color/white&lt;/item&gt;//文字白色 &lt;item name="android:background"&gt;@color/black&lt;/item&gt;//背景黑色 &lt;item name="android:layout_width"&gt;wrap_content&lt;/item&gt;//宽度为文本宽度 ...

    黑马程序员 安卓学院 万元哥项目经理 分享220个代码实例

    |--图片之获取SD卡所有及边界可调及压缩和软引用和内存回收 |--图片的LRU算法内存保存和读取 |--图片的缩放处理(防内存溢出) |--多媒体应用设计图 |--多线程下载 |--多线程下载及断点续传 |--多线程之AsyncTask的...

    黎活明android教程的全程PPT

    采用ListView实现数据列表显示 2&gt; 采用ContentProvider对外共享数据 第四天 1&gt; 往通信录添加联系人,和获取联系人 2&gt; 网络--获取数据(图片、网页、xml、Json等) 3&gt; 如何把数据通过HTTP协议提交到网络上的Web...

    SwissArmyKnife-android免root兼容所有版本ui调试工具.zip

    可以直接在android手机屏幕上显示当前Activity中所有控件(不管是否隐藏)的边界,内外边距大小,每一个控件大小,图片大小,字体颜色,大小,以及自定义信息。同时可以直接在屏幕上取色,另外还提供了直尺(单位为...

    传智播客Android视频教程-课程源码.rar

    2&gt; 网络--获取数据(图片、网页、xml、Json等) 3&gt; 如何把数据通过HTTP协议提交到网络上的Web应用(get / post ) 数据大于2k的时候 A.通过Get方式提交参数给Web应用 B.通过Post方式提交参数给Web应用 C.使用...

    Android开发资料合集--续

    5、TextProssBar 显示文字 7 6、TextView的效果 9 1、TextView的Html效果 9 2、TextView实现下划线效果: 10 3、Spanned 实现TextView的各种样式 10 7、通过HttpClient从指定server获取数据 13 8、隐藏小键盘 13 9、...

    Android实现可以图文混合和长截图的日记本App,优秀安卓课程设计!

    4.使用了各种Bitmap类操作方法压缩、解析、优化、获取图片 5.ListView长按实现Actionbar多选删除 6.在编辑框贴上图片时将图片自动生成一个文件名存在/sdcard/myImage/文件夹 7.利用SpannableString、ImageSpan和...

Global site tag (gtag.js) - Google Analytics