1
我想以網格格式顯示多個圖像,每行2個圖像。我如何使用Android查詢執行此操作?現有的例子是不夠的,缺乏適當的文件...Android查詢:網格顯示(圖像)
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"
/>
IdentifyAnimals.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);
}
}
參考:http://code.google.com/p/android-query/
謝謝。你能給我提供關於如何動態顯示字符串數組或類似圖像的代碼嗎? – chuckfinley
當然。看看我更新的答案。 – VikramV
我創建了ImageListAdapter類 - 我現在如何填充網格?對不起,我在Android開發中是全新的:) – chuckfinley