我想使用排氣,可以拉入儘可能多的圖像,然後在水平滾動視圖中設置它們的Android應用程序。到目前爲止,我讓他們進來,但不管我做什麼,都不會讓我滾動它。試圖有一個水平滾動視圖動態圖片
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="@+id/containerLayout" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/textView1"
android:id="@+id/scrollLayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/niv_large"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center" />
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
的Java文件
public class AppActivity extends Activity
{
private RequestQueue mRequestQueue;
private ImageLoader imageLoader;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
mRequestQueue = Volley.newRequestQueue(this);
imageLoader = new ImageLoader(mRequestQueue, new DiskBitmapCache(getCacheDir(), 0));
// final ImageView networkimage = ImageView.class.cast(findViewById(R.id.niv_large));
// imageLoader.get("http://files.vividscreen.com/soft/b0d52a794a2f44f1a208d1fdf6088125/The-Dark-Knight-Batman-768x1280th.jpg", ImageLoader.getImageListener(networkimage, R.drawable.ic_launcher, R.drawable.ic_launcher));
ArrayList<String> imageUrls = new ArrayList<String>();
imageUrls.add("http://images.cpcache.com/merchandise/514_400x400_Peel.jpg?region=name:FrontCenter,id:28298128,w:16");
imageUrls.add("http://images.cpcache.com/merchandise/514_400x400_NoPeel.jpg?region=name:FrontCenter,id:25042524,w:16");
imageUrls.add("http://michaelkonik.com/wp-content/uploads/2006/06/2014-World-Cup-Logo-400x400.jpg");
//imageUrls.add("http://hdwallsize.com/wp-content/uploads/2013/03/Barcelona-Wallpaper-HD-Lionel-Messi.jpg");
//add other image urls as above until done
LinearLayout containerLayout = new LinearLayout(this);
LinearLayout.LayoutParams lParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
setContentView(containerLayout, lParams);
for(int i = 0; i < imageUrls.size(); i++)
{
ImageView image = new ImageView(this);
//Log.e("Checking image stuffs for null", "Image= " + image + " url=" + imageUrls.get(i) + "imageLoader=" + ImageLoader.getImageListener(image, R.drawable.ic_launcher, R.drawable.ic_launcher));
imageLoader.get(imageUrls.get(i), ImageLoader.getImageListener(image, R.drawable.ic_launcher, R.drawable.ic_launcher));
containerLayout.addView(image );
}
// icon loading, icon error
}
的LinearLayout myContainer中= findViewById(R.id.myContainer);這條線給我一個錯誤,說不能從視圖轉換爲LinearLayout – user2554063
這是正確的,你應該將它轉換爲LinearLayout。我忘了包括這一點。我會編輯答案。 –