예제 #1
0
  protected void buildMultiPic(final GridLayout gridLayout) {
    gridLayout.setVisibility(View.VISIBLE);
    // 获取当前屏幕尺寸
    DisplayMetrics metrics = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(metrics);
    // 设置图片的宽度和高度
    int picWidth = metrics.widthPixels / 3 - 48;

    for (int i = 0; i < 9; i++) {
      // 获取View
      SimpleDraweeView simpleDraweeView = (SimpleDraweeView) gridLayout.getChildAt(i);
      // 设置布局参数
      GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams();
      layoutParams.width = picWidth;
      layoutParams.height = picWidth;
      layoutParams.setMargins(8, 8, 8, 8);
      simpleDraweeView.setLayoutParams(layoutParams);
      // 设置图片数据源
      simpleDraweeView.setImageURI(Uri.parse(Image.imageThumbUrls[i]));
      // 准备传递数据
      final ImageViewPageMessage imageViewPageMessage =
          new ImageViewPageMessage(Image.imageThumbUrls, i);
      simpleDraweeView.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              EventBus.getDefault().postSticky(imageViewPageMessage);
              Intent intent = new Intent(mContext, ImageViewPagerActivity.class);
              mContext.startActivity(intent);
            }
          });
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    characters = new ArrayList<CharTextView>();
    mainLayout = new LinearLayout(this);
    setContentView(mainLayout);
    mainLayout.setOrientation(LinearLayout.VERTICAL);
    mainLayout.setId(442);
    grid = new GridLayout(this);
    GridLayout.LayoutParams gridParams =
        new GridLayout.LayoutParams(GridLayout.spec(3), GridLayout.spec(7));
    grid.setId(444);
    int counter = 0;
    for (int i = 0; i < 7; ++i) {
      for (int j = 0; j < 2; ++j) {
        CharTextView iv = new CharTextView(this);
        Bitmap joeAvatar = BitmapFactory.decodeResource(getResources(), R.drawable.joe);
        Character joe = new Character(joeAvatar, "Joe Nash", 24, "United Kingdom");
        iv.setCharacterCell(joe);
        iv.setId(50 + counter);
        GridLayout.LayoutParams buttonparams =
            new GridLayout.LayoutParams(GridLayout.spec(j), GridLayout.spec(i));
        buttonparams.height = 200;
        buttonparams.width = 150;
        iv.setOnClickListener(this);
        grid.addView(iv, buttonparams);
        characters.add(iv);
        counter++;
      }
    }

    heroLayout = new FrameLayout(this);
    heroLayout.setId(443);
    FrameLayout.LayoutParams frameParams =
        new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    frameParams.height = 600;
    ImageView portrait = new ImageView(this);
    portrait.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.joenash));
    heroLayout.addView(portrait);

    Button fightButton = new Button(this);
    fightButton.setText(R.string.fight);
    ViewGroup.LayoutParams buttonParams =
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    buttonParams.height = 150;
    buttonParams.width = 650;

    mainLayout.addView(heroLayout, frameParams);
    mainLayout.addView(grid, gridParams);
    mainLayout.addView(fightButton, buttonParams);
    // znameto
    //        heroLayout.setBackground();
    // String variable = "variable"
    // int Button = getResources().getIdentifier(variable, "drawable", getPackageName());
  }