2014-09-25 87 views
0

我寫了這樣的xml佈局。我知道gridView是可滾動的組件。但我想使用多個GridView並滾動包含textview。爲它,使用scrollview。 但問題是,gridview高度變得fixed.How我可以創建gridview高度作爲它的size.Please幫我從這些問題短路。佈局中的多個gridview

感謝提前:)

But i am getting these type of view. /i.stack.imgur.com/rjLBu.jpg

+0

您可以使用片段。 – rup35h 2014-09-25 09:16:55

+0

如何只使用片段將解決我的問題?? – 2014-09-25 11:35:40

回答

1

試試這個,看看是否有幫助:

public void createTableRow_you(int no) { 

      tr_u = new TableRow(this); 
      LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT 
        , LayoutParams.WRAP_CONTENT); 

      tr_u.setLayoutParams(lp); 
      tr_u.setWeightSum((float) 1.0); 
      tr_u.setPadding(10, 0, 10, 0); 
      tr_u.setGravity(Gravity.CENTER_VERTICAL); 

      ImageView img1= new ImageView(this); 

      imag1.setPadding(10, 10, 10, 10); 



      if (density == DisplayMetrics.DENSITY_HIGH) { 
       imag1.setLayoutParams(new TableRow.LayoutParams(125, 125)); 

      }else { 
       imag1.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 

      } 

      if (no < photo_icon_u.size()) { 
       img1.setImageDrawable(photo_icon_u.get(no)); 
       img1.setId(Integer.parseInt(photoID_profile.get(no))); 
       img1.setClickable(true); 
       img1.setOnClickListener(this); 
       img1.setTag("profile"); 

      }else { 
       img1.setImageResource(R.drawable.icon); 
       img1.setVisibility(View.GONE); 
      } 


      ImageView img2= new ImageView(this); 

      imag2.setPadding(10, 10, 10, 10); 


      if (density == DisplayMetrics.DENSITY_HIGH) { 
       imag2.setLayoutParams(new TableRow.LayoutParams(125, 125)); 
      }else { 
       imag2.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
      } 

      if (no+1 < photo_icon_u.size()) { 
       imag2.setImageDrawable(photo_icon_u.get(no+1)); 
       imag2.setId(Integer.parseInt(photoID_profile.get(no+1))); 
       imag2.setClickable(true); 
       imag2.setOnClickListener(this); 
       imag2.setTag("profile"); 

      }else { 
       imag2.setImageResource(R.drawable.icon); 
       imag2.setVisibility(View.GONE); 
      } 

      ImageView imag3= new ImageView(this); 

      img3.setPadding(10, 10, 10, 10); 

      if (density == DisplayMetrics.DENSITY_HIGH) { 
       imag3.setLayoutParams(new TableRow.LayoutParams(125, 125)); 
      }else { 
       img3.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
      } 

      if (no+2 < photo_icon_u.size()) { 
       imag3.setImageDrawable(photo_icon_u.get(no+2)); 
       imag3.setId(Integer.parseInt(photoID_profile.get(no+2))); 
       imag3.setClickable(true); 
       imag3.setOnClickListener(this); 
       imag3.setTag("profile"); 
      }else { 
       img3.setImageResource(R.drawable.icon); 
       img3.setVisibility(View.GONE); 
      } 

      tr_u.addView(imag1); 
      tr_u.addView(imag2); 
      tr_u.addView(imag3); 

      tb_photo_u.addView(tr_u, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); 
     } 
+0

試試這可能會有幫助 – 2014-09-25 09:22:08