2013-03-12 4 views
6

मैं इस कोड है कि imageView विजेट में करने के लिए एक छवि लोड लिखा है अंदर:ImageViews गतिशील बनाएं एक पाश

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.gallery); 
    i = (ImageView)findViewById(R.id.imageView1); 

    new get_image("https://www.google.com/images/srpr/logo4w.png") { 
     ImageView imageView1 = new ImageView(GalleryActivity.this); 

     ProgressDialog dialog = ProgressDialog.show(GalleryActivity.this, "", "Loading. Please wait...", true); 

     protected void onPreExecute(){ 
      super.onPreExecute(); 
     } 

     protected void onPostExecute(Boolean result) { 
      i.setImageBitmap(bitmap); 
     dialog.dismiss(); 
     } 
    }.execute(); 


} 

बू अब, मैं कई छवियों को लोड करना चाहते हैं। इस के लिए मैं गतिशील छवि दृश्य बना की जरूरत है, लेकिन मैं कैसे नहीं पता ...

मैं पाश के लिए मेरे कोड एक अंदर चलाना चाहते हैं:

for(int i;i<range;i++){ 
    //LOAD SEVERAL IMAGES. READ URL FROM AN ARRAY 
} 

मेरी मुख्य समस्या यह गतिशील रूप से एक पाश के अंदर कई ImageViews पैदा कर रही है

+0

वहाँ एक विशेष कारण है क्यों एंड्रॉइड के सूची नियंत्रण में निर्मित किया जा सकता है? – Premsuraj

+0

@Premsuraj: नहीं, क्या मैं इस उद्देश्य के लिए विजेट में निर्मित का उपयोग कर सकता हूं? कैसे? – Fcoder

+0

आपको कई छवि दृश्यों की आवश्यकता क्यों है? उद्देश्य क्या है? क्या आपको सूची में छवियों को प्रदर्शित करने की आवश्यकता है? –

उत्तर

14

आप लेआउट, छवि संसाधन और छवियों की कोई संशोधित कर सकते हैं (और साथ गतिशील हो सकता है) अपनी आवश्यकता के अनुसार ...

LinearLayout layout = (LinearLayout)findViewById(R.id.imageLayout); 
for(int i=0;i<10;i++) 
{ 
    ImageView image = new ImageView(this); 
    image.setLayoutParams(new android.view.ViewGroup.LayoutParams(80,60)); 
    image.setMaxHeight(20); 
    image.setMaxWidth(20); 

    // Adds the view to the layout 
    layout.addView(image); 
} 
+0

हाय हुसैन की तरह। आप setMaxHeight और setMaxWidth सेट क्यों करते हैं? –

+0

@ Mitulátbáti: http://developer.android.com/reference/android/widget/ImageView.html#setMaxHeight(int) –

+0

क्या हम उस छविदृश्य में मार्जिन सेट कर सकते हैं? –

0

यदि आपकी आवश्यकता सूची या ग्रिडव्यू में दिखाया गया है तो आपको आलसी लोडिंग सूची या ग्रिड के लिए जाना चाहिए।

कृपया नीचे दिए गए लिंक से गुज़रें।

https://github.com/thest1/LazyList

https://github.com/abscondment/lazy-gallery

+0

मैं स्क्रॉलव्यूअर में कई छवियां दिखाना चाहता हूं। Instagram ऐप – Fcoder

1

आप ImageViews

ImageView image = new ImageView(this); 
LinearLayout.LayoutParams vp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 
image.setLayoutParams(vp); 
image.setMaxHeight(50); 
image.setMaxWidth(50); 
// other image settings 
image.setImageDrawable(drawable); 
theLayout.addView(image); 

बनाने के लिए जहां theLayout लेआउट आप अपनी छवि विचारों में जोड़ना चाहते हैं है इस कोड का उपयोग कर सकते हैं।

अधिक अनुकूलन के लिए dev पृष्ठ देखें, जहां सभी संभावित विकल्प सूचीबद्ध हैं।

0

प्रयास करें इस

rootLayout = (LinearLayout) view1.findViewById(R.id.linearLayout1); 

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
      LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); 
    params.gravity = Gravity.CENTER_VERTICAL; 

    params.setMargins(0, 0, 60, 0); 


    for(int x=0;x<2;x++) { 
     ImageView image = new ImageView(getActivity()); 

     image.setBackgroundResource(R.drawable.ic_swimming); 
     rootLayout.addView(image); 
    } 
संबंधित मुद्दे