android70圖片
㈠ android progressbar的白色背景怎麼去掉
下面這個圖片是progressbar的各種樣式,不知道能不能滿足您的要求,例子來自於android學習手冊,360手機助手中可以下載,裡面有108個android例子,點擊源碼可以看源碼,點擊文檔可以看文檔。
1、說明
在某些操作的進度中的可視指示器,為用戶呈現操作的進度,還它有一個次要的進度條,用來顯示中間進度,如在流媒體播放的緩沖區的進度。一個進度條也可不確定其進度。在不確定模式下,進度條顯示循環動畫。這種模式常用於應用程序使用任務的長度是未知的。
2、XML重要屬性
android:progressBarStyle:默認進度條樣式
android:progressBarStyleHorizontal:水平樣式
3 重要方法
getMax():返回這個進度條的范圍的上限
getProgress():返回進度
getSecondaryProgress():返回次要進度
incrementProgressBy(int diff):指定增加的進度
isIndeterminate():指示進度條是否在不確定模式下
setIndeterminate(boolean indeterminate):設置不確定模式下
setVisibility(int v):設置該進度條是否可視
4 重要事件
onSizeChanged(int w, int h, int oldw, int oldh):當進度值改變時引發此事件
5進度條的樣式
Widget.ProgressBar.Horizontal長形進度
Androidxml 布局:
<ProgressBar
android:id="@+id/progress_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Horizontal "
/>
源碼:
private ProgressBar mProgress;
private int mProgressStatus=0;
private Handler mHandler=newHandler();
@Override
protected void onCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mProgress=(ProgressBar)findViewById(R.id.progress_bar);
new Thread(new Runnable(){
@Override
public void run(){
while(mProgressStatus<100){
mProgressStatus=doWork();
mHandler.post(new Runnable(){
@Override
public void run(){
mProgress.setProgress(mProgressStatus);
}
});
}
}
}).start();
}
效果圖:
帶第二進度的進度條
xml配置如下:
<ProgressBar
android:id="@+id/progress_bar_with_second"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:progress="40"
android:secondaryProgress="70"
android:paddingTop="20dp"
android:paddingBottom="20dp"/>
這里我們設置了初始的進度為40,android:progress的值在mini和max之間即mini<=progressvalue<=max
設置了第二進度條的進度值為70,該值也在mini和max之間。
效果如下:
不確定模式進度條
xml配置文件:
<ProgressBar
android:id="@+id/progress_bar_indeterminate"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:indeterminateBehavior="cycle"
android:paddingBottom="20dp"
android:paddingTop="20dp"
android:progress="40" />
這里通過android:indeterminate="true"設置了當前為無模式進度條
效果如圖:
普通圓形進度:Widget.ProgressBar.Inverse
<ProgressBar
android:id="@+id/progress_bar1"
style="@android:style/Widget.ProgressBar.Inverse"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:progress="50"
android:background="#ff00ff"
android:paddingTop="4dp" />
通過android:backgroup設置了背景色
㈡ Android中壓縮圖片指定大小
注意看這句話,bit.compress(CompressFormat.PNG, 100, baos);
那裡的數字表示 如果不壓縮是100,表示壓縮率為0。
如果是70,就表示壓縮率是70,表示壓縮30%;
所以你的倒數第二句話表示沒有壓縮。
以下是我壓縮的方法,望採納。
/**
* 圖像壓縮並保存到本地
* 返回處理過的圖片
*
*/
private Bitmap
saveImage(String fileName,Bitmap bit) {
File file = new
File(fileName);
if (!file.exists()) {
try
{
file.createNewFile();
} catch (IOException e)
{
e.printStackTrace();
}
}
try
{
ByteArrayOutputStream stream = new
ByteArrayOutputStream();
bit.compress(CompressFormat.JPEG, 70,
stream);
// 70 是壓縮率,表示壓縮30%; 如果不壓縮是100,表示壓縮率為0
FileOutputStream os =
new
FileOutputStream(file);
os.write(stream.toByteArray());
os.close();
return
bit;
} catch (Exception e) {
file = null;
return
null;
}
}
㈢ android SpannableString圖片顯示不全
很簡單,給EditText設置padding,或者上面遮住了就設置paddingTop,以此類推。
㈣ android如何實現圖片預覽
eoe 里邊有很多例子 http://www.eoeandroid.com/forum.php?mod=viewthread&tid=245578
㈤ 【Android開發】怎麼在ListView中做一個圖片批量上傳的隊列
先是兩個layout:
1、main.xml
復制代碼
復制代碼
1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:orientation="vertical"
4 android:layout_width="fill_parent"
5 android:layout_height="fill_parent">
6 <ListView
7 android:layout_width="fill_parent"
8 android:layout_height="fill_parent"
9 android:focusable="false"
10 android:id="@+id/lvImageList" >
11 </ListView>
12 </LinearLayout>
復制代碼
復制代碼
2、listitem.xml
復制代碼
復制代碼
1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:orientation="horizontal"
4 android:layout_width="fill_parent"
5 android:layout_height="?android:attr/listPreferredItemHeight">
6 <ImageView
7 android:id="@+id/itemImgImageInfo"
8 android:layout_marginTop="4dip"
9 android:layout_marginBottom="4dip"
10 android:layout_width="?android:attr/listPreferredItemHeight"
11 android:layout_height="?android:attr/listPreferredItemHeight">
12 </ImageView>
13 <TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/android"
14 android:layout_width="fill_parent"
15 android:layout_height="fill_parent"
16 android:paddingLeft="4dip"
17 android:mode="twoLine">
18 <CheckedTextView
19 android:id="@+id/itemChkImageInfo"
20 android:layout_width="fill_parent"
21 android:layout_height="wrap_content"
22 android:gravity="center_vertical"
23 android:textAppearance="?android:attr/textAppearanceSmall"
24 android:checkMark="?android:attr/listChoiceIndicatorMultiple">
25 </CheckedTextView>
26 <TextView
27 android:id="@+id/itemTxtImageInfo"
28 android:layout_width="fill_parent"
29 android:layout_height="wrap_content"
30 android:gravity="center_vertical|top"
31 android:layout_marginBottom="4dip"
32 android:layout_below="@+id/itemChkImageInfo"
33 android:textAppearance="?android:attr/textAppearanceSmall">
34 </TextView>
35 </TwoLineListItem>
36 </LinearLayout>
復制代碼
復制代碼
接著是代碼:
復制代碼
復制代碼
1 package com.android.MultipleChoiceImageList;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.List;
6 import java.util.Map;
7
8 import android.app.Activity;
9 import android.content.Context;
10 import android.database.Cursor;
11 import android.graphics.Bitmap;
12 import android.net.Uri;
13 import android.os.Bundle;
14 import android.provider.MediaStore;
15 import android.provider.MediaStore.Images;
16 import android.view.LayoutInflater;
17 import android.view.View;
18 import android.view.ViewGroup;
19 import android.widget.AdapterView;
20 import android.widget.CheckedTextView;
21 import android.widget.ImageView;
22 import android.widget.ListView;
23 import android.widget.SimpleAdapter;
24 import android.widget.TextView;
25 import android.widget.AdapterView.OnItemClickListener;
26
27 public class MainActivity extends Activity {
28
29 private ListView lvImageList;
30
31 private String imageID= "imageID";
32 private String imageName = "imageName";
33 private String imageInfo = "imageInfo";
34
35 private ArrayList<String> fileNames = new ArrayList<String>();
36
37 private mAdapter;
38
39 /** Called when the activity is first created. */
40 @Override
41 public void onCreate(Bundle savedInstanceState) {
42 super.onCreate(savedInstanceState);
43 setContentView(R.layout.main);
44
45 lvImageList=(ListView) this.findViewById(R.id.lvImageList);
46 lvImageList.setItemsCanFocus(false);
47 lvImageList.setOnItemClickListener(new OnItemClickListener() {
48 @Override
49 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
50
51 CheckedTextView checkedTextView = (CheckedTextView) view.findViewById(R.id.itemChkImageInfo);
52 checkedTextView.toggle();
53 mAdapter.setCheckItem(position, checkedTextView.isChecked());
54 }
55 });
56 try{
57 String[] from = {imageID, imageName, imageInfo};
58 int[] to = {R.id.itemImgImageInfo, R.id.itemChkImageInfo, R.id.itemTxtImageInfo};
59 mAdapter = new (MainActivity.this, GetImageList(), R.layout.listitem, from, to);
60 lvImageList.setAdapter(mAdapter);
61 }
62 catch(Exception ex){
63 return;
64 }
65 }
66
67 //獲取圖片列表
68 private ArrayList<Map<String, String>> GetImageList(){
69
70 ArrayList<Map<String, String>> imageList = new ArrayList<Map<String,String>>();
71 HashMap<String, String> imageMap;
72
73 //讀取SD卡中所有圖片
74 Uri uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
75 String[] projection = { MediaStore.Images.Media._ID, MediaStore.Images.Media.DISPLAY_NAME,MediaStore.Images.Media.DATA, MediaStore.Images.Media.SIZE};
76 String selection = MediaStore.Images.Media.MIME_TYPE + "=?";
77 String[] selectionArg ={"image/jpeg"};
78 Cursor mCursor = this.managedQuery(uri, projection, selection, selectionArg, MediaStore.Images.Media.DISPLAY_NAME);
79 imageList.clear();
80 if (mCursor != null) {
81 mCursor.moveToFirst();
82 while (mCursor.getPosition() != mCursor.getCount())
83 {
84 imageMap= new HashMap<String, String>();
85 imageMap.put(imageID, mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media._ID)));
86 imageMap.put(imageName, mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME)));
87 imageMap.put(imageInfo, " " + (mCursor.getLong(mCursor.getColumnIndex(MediaStore.Images.Media.SIZE))/1024)+"KB");
88 imageList.add(imageMap);
89 fileNames.add(mCursor.getString(mCursor.getColumnIndex(MediaStore.Images.Media.DATA)));
90 mCursor.moveToNext();
91 }
92 mCursor.close();
93 }
94 return imageList;
95 }
96
97 //可多選圖片列表適配器
98 class extends SimpleAdapter {
99
100 private Map<Integer, Boolean> map;
101 private List<Integer> state;
102 private List<? extends Map<String, ?>> mList;
103
104 LayoutInflater mInflater;
105
106 public (Context context, List<Map<String, String>> data, int resource, String[] from, int[] to) {
107 super(context, data, resource, from, to);
108 map = new HashMap<Integer, Boolean>();
109 mInflater = LayoutInflater.from(context);
110 mList = data;
111 for(int i = 0; i < data.size(); i++) {
112 map.put(i, false);
113 }
114 state = new ArrayList<Integer>();
115 }
116
117 @Override
118 public int getCount() {
119 return mList.size();
120 }
121
122 @Override
123 public Object getItem(int position) {
124 return position;
125 }
126
127 @Override
128 public long getItemId(int position) {
129 return position;
130 }
131
132 //設置條目選中狀態
133 public void setCheckItem(int position, Boolean isChecked){
134 map.put(position, isChecked);
135 if (state.contains(position))
136 state.remove((Object)position);
137 if (isChecked){
138 state.add(position);
139 }
140 }
141
142 //獲取列表中已選中條目
143 public long[] getCheckItemIds(){
144 int count = state.size();
145 long[] ids = new long[count];
146 for (int i = 0; i < count; i++) {
147 ids[i]= (long)state.get(i);
148 }
149 return ids;
150 }
151
152 @Override
153 public View getView(int position, View convertView, ViewGroup parent) {
154 if(convertView == null) {
155 convertView = mInflater.inflate(R.layout.listitem, null);
156 }
157
158 CheckedTextView checkedTextView = (CheckedTextView) convertView.findViewById(R.id.itemChkImageInfo);
159 checkedTextView.setChecked(map.get(position));
160 checkedTextView.setText((String)mList.get(position).get(imageName));
161
162 TextView textView = (TextView) convertView.findViewById(R.id.itemTxtImageInfo);
163 textView.setText((String)mList.get(position).get(imageInfo));
164
165 //顯示圖片縮略圖
166 ImageView image = (ImageView) convertView.findViewById(R.id.itemImgImageInfo);
167 Bitmap bm = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(), Long.parseLong((String)mList.get(position).get(imageID)), Images.Thumbnails.MICRO_KIND, null);
168 image.setImageBitmap(bm);
169
170 return convertView;
171 }
172 }
173 }
㈥ android 自帶的分享功能如何實現分享圖片
bgimg0=getImageFromAssetsFile("Cat_Blink/cat_blink0000.png");
/**
*從Assets中讀取圖片
*/
(StringfileName)
{
Bitmapimage=null;
AssetManageram=getResources().getAssets();
try
{
InputStreamis=am.open(fileName);
image=BitmapFactory.decodeStream(is);
is.close();
}
catch(IOExceptione)
{
e.printStackTrace();
}
returnimage;
}
上面的代碼是從assets中獲取圖片的代碼,下面的代碼是分享圖片的代碼:
/**
*分享功能
*
*@paramcontext
*上下文
*@paramactivityTitle
*Activity的名字
*@parammsgTitle
*消息標題
*@parammsgText
*消息內容
*@paramimgPath
*圖片路徑,不分享圖片則傳null
*/
publicvoidshareMsg(StringactivityTitle,StringmsgTitle,StringmsgText,
StringimgPath){
Intentintent=newIntent(Intent.ACTION_SEND);
if(imgPath==null||imgPath.equals("")){
intent.setType("text/plain");//純文本
}else{
Filef=newFile(imgPath);
if(f!=null&&f.exists()&&f.isFile()){
intent.setType("image/jpg");
Uriu=Uri.fromFile(f);
intent.putExtra(Intent.EXTRA_STREAM,u);
}
}
intent.putExtra(Intent.EXTRA_SUBJECT,msgTitle);
intent.putExtra(Intent.EXTRA_TEXT,msgText);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(intent,activityTitle));
}
系統的分享,你想要分享圖片需要先把圖片存到本地才能分享
㈦ android 獲取的圖片尺寸比圖片屬性顯示的尺寸大很多
起因是測試在測試過程中發現需要裁剪的圖片看不到,但是還能繼續裁剪。
所以就檢查代碼,發現了bitmap的width和Height有3000多。
然後試了下把圖片改成300*300的就顯示正常,
所以我們需要讓圖片根據大小不同,機器不同而改變圖片的寬高
//設置解析度
//1.獲取系統解析度
Resources resources = this.getResources();
DisplayMetrics dm = resources.getDisplayMetrics();
//2.獲取圖片解析度
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;// 這個方式不會在內存創建一張圖片,
Bitmap bitmap = BitmapFactory.decodeFile(filePath, options); //此時返回的bitmap為null,但是option會保留一部分參數
//3.確定解析度
int height = options.outHeight;
int width = options.outWidth;
if(options.outHeight>dm.heightPixels*1.5f){//當圖片大小比屏幕大1.5倍的時候,直接以系統高度為高度
height = dm.heightPixels;
}
if (options.outWidth>dm.widthPixels*1.5f){
width = dm.widthPixels;
}
options.inJustDecodeBounds = false;