0

I wrote xml layout like this. I know gridView is scrollable component. but I want to use multiple gridview and to scroll include textview. for it, using scrollview. But the problem is that gridview height become fixed.How can i create the gridview height as its size.Please help me to short out from these problem.

Thanks in advance :)

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

Ravindra Kushwaha
  • 7,846
  • 14
  • 53
  • 103

2 Answers2

1

Try this, see if it helps :

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));
        }
m4rtin
  • 2,445
  • 22
  • 34
1

ExpandableHeightGridView seems to work great for everyone. I think it should solve your problem.

Community
  • 1
  • 1
0101100101
  • 5,786
  • 6
  • 31
  • 55