随笔-12  评论-7  文章-0  trackbacks-0
  置顶随笔
摘要: 最近一个项目中,从网上下载一个图片,然后展示给用户看,那个图片本来是iphone里的,拿到android上来,一拉伸就出问题了,scrollview的顶部和底部出现了奇怪的黑块,如图:在网上找了很资料都没解决,后来在一个外国网站找到结果,分享一下。代码:<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="v阅读全文
posted @ 2012-02-10 15:25 橫龙村夫 阅读(231) 评论(0) 编辑
摘要: 实现原理:在onItemSelected事件中,选中galerry中的图片时,把选中的图片放大,把没有选中的缩小。 以下是关键代码1publicvoidonItemSelected(AdapterView<?>parent,Viewview,intposition,2longid){3//选中Gallery中某个图像时,放大显示该图像4ImageViewimageview=(ImageView)view;5((ImageView)view).setImageDrawable((Drawable)product_image_list.get(position));6view.setL阅读全文
posted @ 2012-02-06 11:20 橫龙村夫 阅读(364) 评论(0) 编辑
  2012年2月10日

最近一个项目中,从网上下载一个图片,然后展示给用户看,那个图片本来是iphone里的,拿到android上来,一拉伸就出问题了,scrollview的顶部和底部出现了奇怪的黑块,如图:

在网上找了很资料都没解决,后来在一个外国网站找到结果,分享一下。

代码:

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<ScrollView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    >
    <ImageView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/demo"
    android:adjustViewBounds="true"
    android:scaleType="centerInside"></ImageView>
    </ScrollView>
</LinearLayout>

android:adjustViewBounds="true"这句很关键

奉送美女图片一张:/Files/ProgramBull/demo.jpg

 

posted @ 2012-02-10 15:25 橫龙村夫 阅读(231) 评论(0) 编辑
  2012年2月6日

之前一直困扰listview刷新后位置的问题,现在才明白,原来不能重新设置listview的adapter,而应该用notifyDataSetChanged()来刷新,这样位置就不会置顶。

下面做了一个测试的例子,点击最后一条记录,会增加一条新的记录,

代码如下:

1.TestAdapter

 

package com.TestAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.AbsListView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class TestAdapter extends Activity {
    /** Called when the activity is first created. */
    private int[] images ;
    private ListView listview;
    private MyAdapter adapter;
    List<Map<String,Integer>> al;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        images =  new int[]{android.R.drawable.ic_btn_speak_now,
                android.R.drawable.alert_light_frame,
                android.R.drawable.arrow_down_float,
                android.R.drawable.arrow_up_float,
                android.R.drawable.btn_star_big_off,
                android.R.drawable.btn_star_big_on,
                android.R.drawable.button_onoff_indicator_off,
                android.R.drawable.button_onoff_indicator_on,
                android.R.drawable.checkbox_off_background,
                android.R.drawable.checkbox_on_background,
                android.R.drawable.ic_btn_speak_now,
                android.R.drawable.ic_delete};
        listview = (ListView)findViewById(R.id.listview);
        al = new ArrayList<Map<String,Integer>>();
        for(int i=0; i<12; i++){
            HashMap<String,Integer > map = new HashMap<String,Integer>();
            map.put(""+i, images[i]);
            al.add(map);
        }

        adapter = new MyAdapter(this, al, R.layout.list_item, new String[]{"imageview", "tv"}, 
                new int[]{R.id.imageview, R.id.tv});
        listview.setAdapter(adapter);
        listview.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int count,
                    long arg3) {
                if(adapter.getCount()==count+1){
                    HashMap<String ,Integer> map = new HashMap<String, Integer>();
                    map.put(""+(adapter.mItemList.size()), android.R.drawable.ic_dialog_email);
                    al.add(map);
                    adapter.mItemList = al;
                    adapter.notifyDataSetChanged();
                    Toast.makeText(TestAdapter.this, "正在刷新", Toast.LENGTH_SHORT).show();
                }                
            }
        });
        
    }
    
    
    private class MyAdapter extends SimpleAdapter{
        int count = 0;
        private List<Map<String, Integer>> mItemList;
        public MyAdapter(Context context, List<? extends Map<String, Integer>> data,
                int resource, String[] from, int[] to) {
            super(context, data, resource, from, to);
            mItemList = (List<Map<String, Integer>>) data;
            if(data == null){
                count = 0;
            }else{
                count = data.size();
            }
        }
        public int getCount() {
            return mItemList.size();
        }

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

        public long getItemId(int pos) {
            return pos;
        }
        
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Map<String ,Integer> map = mItemList.get(position);
            int image  =  map.get(""+position);
            View view = super.getView(position, convertView, parent);
            ImageView imageview = (ImageView)view.findViewById(R.id.imageview);
            TextView tv = (TextView)view.findViewById(R.id.tv);
            imageview.setBackgroundResource(image);
            tv.setText(""+position);
            return view;
        }
    }
}

2.main.xml

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <ListView android:id="@+id/listview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    ></ListView>
    
</LinearLayout>

3.list_item.xml

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <ImageView 
    android:id="@+id/imageview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    </ImageView>
    <TextView
        android:id="@+id/tv" android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    ></TextView>
</LinearLayout>

 

posted @ 2012-02-06 17:08 橫龙村夫 阅读(1706) 评论(0) 编辑

 

实现原理:在onItemSelected事件中,选中galerry中的图片时,把选中的图片放大,把没有选中的缩小。
以下是关键代码
 1     public void onItemSelected(AdapterView<?> parent, View view, int position,
 2             long id) {
 3         // 选中Gallery中某个图像时,放大显示该图像
 4         ImageView imageview = (ImageView)view;
 5         ((ImageView) view).setImageDrawable((Drawable) product_image_list.get(position));
 6         view.setLayoutParams(new Gallery.LayoutParams(520 / 2, 318 / 2));
 7         title.setText((String)product_title.get(position));
 8         info.setText((String)product_info.get(position));
 9         for(int i=0; i<parent.getChildCount();i++){
10             //缩小选中图片旁边的图片
11             ImageView local_imageview = (ImageView)parent.getChildAt(i);
12             if(local_imageview!=imageview){
13                 local_imageview.setLayoutParams(new Gallery.LayoutParams(520/4, 318/4));
14                 local_imageview.setScaleType(ImageView.ScaleType.FIT_CENTER);
15             }
16         }
17     }
18     
19     public void onNothingSelected(AdapterView<?> parent)
20     {
21     }
22     
23     public class ImageAdapter extends BaseAdapter
24     {
25         int mGalleryItemBackground;
26         private Context mContext;
27 
28         public ImageAdapter(Context context)
29         {
30             mContext = context;
31 //            TypedArray typedArray = obtainStyledAttributes(R.styleable.Gallery);
32 //            mGalleryItemBackground = typedArray.getResourceId(
33 //                    R.styleable.Gallery_android_galleryItemBackground, 0);                        
34         }
35         
36         public int getCount()
37         {
38             return product_image_list.size();
39         }
40 
41         public Object getItem(int position)
42         {
43             return position;
44         }
45 
46         public long getItemId(int position)
47         {
48             return position;
49         }
50  
51         public View getView(int position, View convertView, ViewGroup parent)
52         {
53             ImageView imageView = new ImageView(mContext);
54             imageView.setLayoutParams(new Gallery.LayoutParams(520/4, 318/4));//默认都是大图
55             imageView.setImageDrawable((Drawable) product_image_list.get(position));
56             imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
57             return imageView;
58         }
59     }

 

posted @ 2012-02-06 11:20 橫龙村夫 阅读(364) 评论(0) 编辑
  2012年2月2日
http://www.apkbus.com/android-19658-1-1.html
posted @ 2012-02-02 18:03 橫龙村夫 阅读(30) 评论(0) 编辑
  2010年8月2日
比较两个文件是否一样

function AreSameFiles(File1 : TFileName ; File2 : TFileName): Boolean;
var
  MS1 : TMemoryStream;
  MS2 : TMemoryStream;
begin
  Result :
= false;
  MS1 :
= TMemoryStream.Create;
  
try
    MS1.LoadFromFile(File1);
    MS2 :
= TMemoryStream.Create;
    Try
      MS2.LoadFromFile(File2);
      
if MS1.Size=MS2.Size then
      
begin
        Result :
= CompareMem(MS1.Memory , MS2.Memory , MS1.Size);
      
end;
    Finally
      MS2.Free;
    End;
  
finally
    MS1.Free
  
end;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  
if  AreSameFiles(Edit1.Text , Edit2.text) then
  
begin
    ShowMessage(
'一样');
  
end else begin
    SHowMessage(
'不一样');
  
end;
end;

 

posted @ 2010-08-02 09:27 橫龙村夫 阅读(32) 评论(0) 编辑
  2010年7月15日
    只有注册用户登录后才能阅读该文。阅读全文
posted @ 2010-07-15 10:47 橫龙村夫 阅读(55) 评论(0) 编辑
  2010年6月20日
摘要: 代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->functionGetSystemImageList(ImageList:TImageList):Boolean;varvHandle:THandle;vSHFileInfo:TSHFileInfo;...阅读全文
posted @ 2010-06-20 11:31 橫龙村夫 阅读(207) 评论(0) 编辑
  2010年5月6日
摘要: 代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->unitUnit2;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,Id...阅读全文
posted @ 2010-05-06 16:12 橫龙村夫 阅读(180) 评论(2) 编辑
摘要: 在Delphi自带的Indy控件中其实是提供了MD2,MD4,MD5对象的,我们可以直接使用它们来完成MD5的签名算法。而不需要再去找其它的 DLL或是Pas了。 在Uses单元中引用 IdHashMessageDigest,IdGlobal, IdHash 单元,再写如下代码即可以达到MD5的实现。 示例代码 procedure TForm1.Button1Click(Sender: TObje...阅读全文
posted @ 2010-05-06 16:11 橫龙村夫 阅读(314) 评论(0) 编辑
  2010年1月11日
摘要: 前一段时间写一个程序,ImageList中添加PNG图片,Toolbar引用ImageList中的PNG图片时,图片背景是黑色,其实只要设置ImageList的一个属性:ColorDepth设置成cd32Bit就可以了。阅读全文
posted @ 2010-01-11 22:18 橫龙村夫 阅读(459) 评论(1) 编辑
仅列出标题  下一页