10

I want to set two grid view for same layout. I can also able to set that within same lay out but due to scrollable control its look like a "wrap_content".

but i want to show full grid view in a screen one after another like below fig.enter image description here

in above fig. grid view show full height of it. so please help me.

Thank you .

amity
  • 942
  • 1
  • 8
  • 24
  • please any body known about this, if yes then please help me – amity Sep 19 '11 at 11:31
  • Could you add some images..? If you are trying to fit a larger object in screen then scroll bars is the best bet. Another option is re-sizing but makes undesireable effects. – Anoop Chandrika HarisudhanNair Sep 19 '11 at 12:48
  • If you give us a hint of why you need two gridviews then may be we could suggest a better solution.\ – Ron Sep 19 '11 at 13:39
  • do you mean 2 gridviews under each other? – Sherif elKhatib Sep 19 '11 at 14:47
  • Amit, I am not sure what you are wanting to do. Can you explain further? You have two sets of data that are displayed as grid views but the user is confused and does not understand that they are separate data sets? If so, perhaps show one set then let the user swipe to the next set. – ciscogambo Sep 19 '11 at 21:13
  • 1
    hi friends, I want to show no of images in two parts of grid view format. part one has heading "other" below this images to be display and part two has heading "private" and below this images should be desplay. But each grid view must show it full height. – amity Sep 20 '11 at 04:39
  • finally i have done my task using table layout. i have manage table view onprogrssUpdate method. thank you everybody for your support. – amity Sep 21 '11 at 09:58

4 Answers4

4

You cannot have a GridView in a ScrollbarView. So what you want is not possible. You can have the two gridviews to share the screen space equally.

<LinearLayout android:layout_height="fill_parent"
    .... >
    <GridView android:layout_weight="1"
     ....... >
    <GridView android:layout_weight="1"
     ....... >
</LinearLayout>

Update

There is a download asynctask example here. In onProgressUpdate set the downloaded image to its view.

 protected void onProgressUpdate(Integer... progress) {
     setImageToView(bitmapImg, progress[0]); // progress[0] is the index or id.
 }

Update 2

You should do it the hard way. Extend the AdapterView class and measure and layout the items yourself. Here is link for start. The layout now would look like

<ScrollView ....>
    <LinearLayout android:layout_height="fill_parent"
        .... >
        <MyGridView android:layout_height="wrap_content"
         ....... >
        <MyGridView android:layout_height="wrap_content"
         ....... >
    </LinearLayout>
</ScrollView>
Community
  • 1
  • 1
Ron
  • 24,175
  • 8
  • 56
  • 97
2

You can't put a GridView inside a ScrollView because the scroll view will eat all the Vertical TouchEvents. I had to work around this problem as well, my solution was to implement an AdapterView by myself to emulate the gridView behevior without extending ScrollView.

I did it with horizontal LinearLayout inside a vertical LinearLayout and dynamic margin between elements.

that way you will have only a root ScrollView that let you scroll down the layout with all the GridView element.

Mario Lenci
  • 10,422
  • 5
  • 39
  • 50
  • Hi Marioo i don't get you exactly, you are using this layouts inside grid view or in any other layout. please can you explain little bit more. and thank you – amity Sep 26 '11 at 12:37
  • no, i didn't use any GridView. I just re-implemented its behavior by myself by the combination of multiple LinearLayout without the scroll. Actually, after doing that i discovered the TableLayout wich has the same behavior i implemented. TableLayout: http://developer.android.com/reference/android/widget/TableLayout.html http://developer.android.com/resources/tutorials/views/hello-tablelayout.html – Mario Lenci Sep 26 '11 at 16:18
  • tha fact, in my point of view, is that you can't put a vertical scroll view into an other one with vertical scroll. A solution could be to use something that has horizontal scroll ( the new ViewPager for instance) to switch between subsets of images. for the ViewPager you can take a look here: http://blog.stylingandroid.com/archives/537 sorry about my english. ;) – Mario Lenci Sep 26 '11 at 16:24
  • Thanks Marioo, actuly i have implemented this concept using table layout. But i thing you may have some new idea, that's why i have tell you to explain bit more. Thanks for your reply. – amity Sep 27 '11 at 03:49
2

TRY THIS :

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);
          //img1.setLayoutParams(lp);
          img1.setPadding(10, 10, 10, 10);

         // img1.setScaleType(ScaleType.FIT_XY);

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

          }else {
              img1.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);
          //img2.setLayoutParams(lp);
          img2.setPadding(10, 10, 10, 10);
        //  img2.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, (float) 0.33));
        //  img2.setScaleType(ScaleType.FIT_XY);
          if (density == DisplayMetrics.DENSITY_HIGH) {
              img2.setLayoutParams(new TableRow.LayoutParams(125, 125 ));
          }else {
              img2.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));  
          }

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

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

          ImageView img3= new ImageView(this);
         // img3.setLayoutParams(lp);
          img3.setPadding(10, 10, 10, 10);
        //  img3.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, (float) 0.34));
          //img3.setScaleType(ScaleType.FIT_XY);

          if (density == DisplayMetrics.DENSITY_HIGH) {
              img3.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()) {
              img3.setImageDrawable(photo_icon_u.get(no+2));
              img3.setId(Integer.parseInt(photoID_profile.get(no+2)));
              img3.setClickable(true);
              img3.setOnClickListener(this);
              img3.setTag("profile");
          }else {
              img3.setImageResource(R.drawable.icon);
              img3.setVisibility(View.GONE);
          }

          tr_u.addView(img1);
          tr_u.addView(img2);
          tr_u.addView(img3);
        //.  tb_photo_u.addView(tr_u);
          tb_photo_u.addView(tr_u, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
        }
Raj
  • 1,213
  • 2
  • 16
  • 34
0

If you have some other elements with GridView, I recommend using FrameLayout with layout_weight.

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1">

1st
</FrameLayout>
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:layout_marginTop="20dp">
2nd
</FrameLayout>
</LinearLayout>