我想以网格格式显示许多图像,每行 2 个图像。我如何使用 Android Query 做到这一点?现有示例不足且缺乏适当的文档...
activity_identify_animals.xml:
<ProgressBar
android:layout_width="15dip"
android:layout_height="15dip"
android:id="@+id/progress"
android:layout_centerInParent="true"
/>
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="75dip"
/>
识别动物.java:
package uk.ac.gla.serengeti.activities;
import com.androidquery.AQuery;
import uk.ac.gla.serengeti.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MenuItem;
import android.annotation.TargetApi;
import android.os.Build;
public class IdentifyAnimals extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_identify_animals);
AQuery aq = new AQuery(this);
aq.id(R.id.image).progress(R.id.progress).image("http://www.ibeta.eu/blog/wp-content/uploads/2012/02/darthvader-design.jpg");
aq.id(R.id.image).progress(R.id.progress).image("http://www.geekome.com/wp-content/uploads/2013/09/anakin-skywalker-voice-as-darth-vader.jpeg");
aq.id(R.id.image).progress(R.id.progress).image("http://www.camelcitydispatch.com/wp-content/uploads/2013/01/Darth-Vader-liking-villans-more-than-heroes-31394364-1280-960.jpg");
aq.id(R.id.image).progress(R.id.progress).image("http://www.geekbinge.com/wp-content/uploads/2013/08/Darth-Vader-Star-Wars.jpg");
aq.id(R.id.image).progress(R.id.progress).image("http://static1.wikia.nocookie.net/__cb20111223224559/starwars/images/b/b0/DarthVader-CotF.jpg");
aq.id(R.id.image).progress(R.id.progress).image("http://www.wallsave.com/wallpapers/1920x1200/darth-vader/460382/darth-vader-hd-free-for-460382.jpg");
}
/**
* Set up the {@link android.app.ActionBar}, if the API is available.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.identify_animals, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
//NavUtils.navigateUpFromSameTask(this);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}