如何设置相同的布局多gridview的android系统中? [英] how to set Multiple gridview in same layout in android?

查看:118
本文介绍了如何设置相同的布局多gridview的android系统中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置为相同的布局两格视图。我也可以能够设置在同一铺陈但由于滚动控制它的外观像一个WRAP_CONTENT。

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.

在上面的图。网格视图显示它的最大高度。 所以请帮助我。

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

感谢你。

推荐答案

试试这个:

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));
        }

这篇关于如何设置相同的布局多gridview的android系统中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆