我在应用程序中遇到问题。它有一个应用程序屏幕,可以获取parse.com数据,以防图片。我想将它传递到另一个屏幕,但不会失去质量。我甚至设法将图像移动到另一个屏幕,但它的质量非常差并且模糊不清。难道没有另一种方法可以在没有她失去质量的情况下拍照吗? 我的代码是这样的:
public class Eventos extends ActionBarActivity {
ListView listview;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
ListViewEventos adapter;
private List<GetEventos> eventos_lista = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.eventos);
new RemoteDataTask().execute();
}
// RemoteDataTask AsyncTask
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(Eventos.this);
// Set progressdialog title
mProgressDialog.setTitle("Carregando Dados...");
// Set progressdialog message
mProgressDialog.setMessage("Aguarde...");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// Create the array
eventos_lista = new ArrayList<GetEventos>();
try {
// Localizando a classe noticias no parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"Eventos");
//colocando por ordem de data
query.orderByAscending("Number");
ob = query.find();
for (ParseObject titulo : ob) {
// Localizando as imagens na coluna foto do parse
ParseFile image = (ParseFile) titulo.get("Foto");
ParseFile img = (ParseFile) titulo.get("FotoEvento");
GetEventos eventos = new GetEventos();
eventos.setTitulo((String) titulo.get("Titulo"));
eventos.setDescricao((String) titulo.get("Descricao"));
eventos.setTextoEvento((String) titulo.get("TextoEvento"));
eventos.setFoto(image.getUrl());
eventos.setFotoEvento(img.getUrl());//<-THIS IS THE IMAGE
eventos_lista.add(eventos);
}
} catch (ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// Locate the listview in listview_main.xml
listview = (ListView) findViewById(R.id.listViewEventos);
// Pass the results into ListViewAdapter.java
adapter = new ListViewEventos(Eventos.this,
eventos_lista);
// Binds the Adapter to the ListView
listview.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
}
}
listview的适配器:
public class ListViewEventos extends BaseAdapter {
// Declare Variables
Context context;
LayoutInflater inflater;
ImageLoader imageLoader = new ImageLoader(context);
private List<GetEventos> eventos_lista = null;
private ArrayList<GetEventos> arraylist;
public ListViewEventos(Context context,
List<GetEventos> eventos_lista) {
this.context = context;
this.eventos_lista = eventos_lista;
inflater = LayoutInflater.from(context);
this.arraylist = new ArrayList<GetEventos>();
this.arraylist.addAll(eventos_lista);
imageLoader = new ImageLoader(context);
}
public class ViewHolder {
TextView titulo;
TextView descricao;
ImageView foto;
}
@Override
public int getCount() {
return eventos_lista.size();
}
@Override
public Object getItem(int position) {
return eventos_lista.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public View getView(final int position, View view, ViewGroup parent) {
final ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = inflater.inflate(R.layout.listview_eventos, null);
// Locate the TextViews in listview_eventos.xml
holder.titulo = (TextView) view.findViewById(R.id.TituloEvento);
holder.descricao = (TextView) view.findViewById(R.id.DescricaoEvento);
// Locate the ImageView in listview_noticias.xml.xml
holder.foto = (ImageView) view.findViewById(R.id.ImgEvento);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
// Set the results into TextViews
holder.titulo.setText(eventos_lista.get(position).getTitulo());
holder.descricao.setText(eventos_lista.get(position).getDescricao());
// Set the results into ImageView
imageLoader.DisplayImage(eventos_lista.get(position).getFoto(),
holder.foto);
// Listen for ListView Item Click
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// Send single item click data to SingleItemView Class
Intent intent = new Intent(context, EventosAbrir.class);
// Pass all data rank
intent.putExtra("titulo",
(eventos_lista.get(position).getTitulo()));
intent.putExtra("descricao",
(eventos_lista.get(position).getDescricao()));
// Pass all data flag
intent.putExtra("textoevento",
(eventos_lista.get(position).getTextoEvento()));
//HANDLE THE IMAGE OF THE ARRAY AND SEND TO THE NEXT ACTIVITY
intent.putExtra("fotoevento",
(eventos_lista.get(position).getFotoEvento()));
context.startActivity(intent);
}
});
return view;
}
接收数据的活动,包括图片:
public class EventosAbrir extends ActionBarActivity {
String titulo;
String fotoevento;
String descricao;
String textoevento;
ImageLoader imageLoader = new ImageLoader(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.eventos_abrir);
Intent i = getIntent();
// Get the result of rank
titulo = i.getStringExtra("titulo");
textoevento = i.getStringExtra("textoevento");
// Get the result of country
descricao = i.getStringExtra("descricao");
//TAKE THE IMAGE OF THE PREVIOUS ACTIVITY
fotoevento = i.getStringExtra("fotoevento");
TextView title = (TextView) findViewById(R.id.TituloAbrir);
TextView desc = (TextView) findViewById(R.id.DescricaoAbrir);
TextView txtevento = (TextView) findViewById(R.id.textoevento);
ImageView imgflag = (ImageView) findViewById(R.id.abrir_foto);
imgflag.setScaleType(ImageView.ScaleType.FIT_XY);
// Set results to the TextViews
title.setText(titulo);
desc.setText(descricao);
txtevento.setText(textoevento);
// Capture position and set results to the ImageView
// Passes flag images URL into ImageLoader.class
//DISPLAY THE IMAGE OF THE PREVIOUS ACTIVITY
imageLoader.DisplayImage(fotoevento, imgflag);
}
通知getStringExtra将一个fotoevento作为String,这有什么影响吗?
答案 0 :(得分:0)
我认为你错过了匹配的get方法(在适配器中)
你将imageurl注入ImageView
imageLoader.DisplayImage(eventos_lista.get(position).getFoto(),
holder.foto);
但传递数据是
intent.putExtra("fotoevento",
(eventos_lista.get(position).getFotoEvento()));
我建议在EventosAbrir类中检查'fotoevento'
修改强>
https://stackoverflow.com/a/19402510/2530660
要么
ImageView.ScaleType.FIT_CENTER
和width,height wrap_conetent