コード例 #1
0
ファイル: IndexAdapter.java プロジェクト: jnksu/Demo
  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);
            }
          });
    }
  }
コード例 #2
0
  @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());
  }
コード例 #3
0
  private void showInvitations() {

    GridLayout.Spec row;
    GridLayout.Spec column;
    GridLayout.LayoutParams params;

    for (Invitation i : invitations) {

      final TextView tempText = new TextView(getApplicationContext());
      tempText.setText(i.getNomFoyer());
      tempText.setTextSize(18);
      row = GridLayout.spec(mainLayout.getRowCount());
      column = GridLayout.spec(0);
      params = new GridLayout.LayoutParams(row, column);
      params.setGravity(Gravity.FILL_HORIZONTAL);
      tempText.setLayoutParams(params);
      mainLayout.addView(tempText);

      Button tempAcceptButton =
          new Button(getApplicationContext(), null, android.R.attr.buttonStyleSmall);
      tempAcceptButton.setText(R.string.show_invitations_accept);
      column = GridLayout.spec(1);
      params = new GridLayout.LayoutParams(row, column);
      tempAcceptButton.setLayoutParams(params);
      tempAcceptButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              accept(tempText.getText().toString(), mainLayout.getFocusedChild());
            }
          });
      mainLayout.addView(tempAcceptButton);

      Button tempRefuseButton =
          new Button(getApplicationContext(), null, android.R.attr.buttonStyleSmall);
      tempRefuseButton.setText(R.string.show_invitations_refuse);
      column = GridLayout.spec(2);
      params = new GridLayout.LayoutParams(row, column);
      tempRefuseButton.setLayoutParams(params);
      tempRefuseButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              refuse(tempText.getText().toString(), mainLayout.getFocusedChild());
            }
          });
      mainLayout.addView(tempRefuseButton);
    }
  }
コード例 #4
0
ファイル: GridActivity.java プロジェクト: youtao/Anroid-Learn
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_grid);

    this.layout = (GridLayout) findViewById(R.id.activity_grid_root);
    for (int i = 0; i < chars.length; i++) {
      Button btn = new Button(this);
      btn.setText(chars[i]);
      btn.setTextSize(40);
      btn.setPadding(5, 35, 5, 35);
      GridLayout.Spec row = GridLayout.spec(i / 4 + 2);
      GridLayout.Spec col = GridLayout.spec(i % 4);
      GridLayout.LayoutParams param = new GridLayout.LayoutParams(row, col);
      param.setGravity(Gravity.FILL);
      this.layout.addView(btn, param);
    }
  }
コード例 #5
0
  // Abstract Method in BaseAdapter
  public View getView(int position, View convertView, ViewGroup parent) {
    if (position >= (mRowCount - PREFETCH_BOUNDARY) && mNewerRequests <= mNewerRequestsProcessed) {
      if (DEBUGLOG) Log.e(TAG, "queryForNewerEvents: ");
      mNewerRequests++;
      queueQuery(new QuerySpec(QUERY_TYPE_NEWER));
    }

    if (position < PREFETCH_BOUNDARY && mOlderRequests <= mOlderRequestsProcessed) {
      if (DEBUGLOG) Log.e(TAG, "queryForOlderEvents: ");
      mOlderRequests++;
      queueQuery(new QuerySpec(QUERY_TYPE_OLDER));
    }

    final View v;
    DayAdapterInfo info = getAdapterInfoByPosition(position);
    if (info != null) {
      int offset = position - info.offset;
      v = info.dayAdapter.getView(offset, convertView, parent);

      // Turn on the past/present separator if the view is a day header
      // and it is the first day with events after yesterday.
      if (info.dayAdapter.isDayHeaderView(offset)) {
        View simpleDivider = v.findViewById(R.id.top_divider_simple);
        View pastPresentDivider = v.findViewById(R.id.top_divider_past_present);
        if (info.dayAdapter.isFirstDayAfterYesterday(offset)) {
          if (simpleDivider != null && pastPresentDivider != null) {
            simpleDivider.setVisibility(View.GONE);
            pastPresentDivider.setVisibility(View.VISIBLE);
          }
        } else if (simpleDivider != null && pastPresentDivider != null) {
          simpleDivider.setVisibility(View.VISIBLE);
          pastPresentDivider.setVisibility(View.GONE);
        }
      }
    } else {
      // TODO
      Log.e(TAG, "BUG: getAdapterInfoByPosition returned null!!! " + position);
      TextView tv = new TextView(mContext);
      tv.setText("Bug! " + position);
      v = tv;
    }

    // If this is not a tablet config don't do selection highlighting
    if (!mIsTabletConfig) {
      return v;
    }
    // Show selected marker if this is item is selected
    boolean selected = false;
    Object yy = v.getTag();
    if (yy instanceof AgendaAdapter.ViewHolder) {
      AgendaAdapter.ViewHolder vh = (AgendaAdapter.ViewHolder) yy;
      selected = mSelectedInstanceId == vh.instanceId;
      vh.selectedMarker.setVisibility((selected && mShowEventOnStart) ? View.VISIBLE : View.GONE);
      if (mShowEventOnStart) {
        GridLayout.LayoutParams lp = (GridLayout.LayoutParams) vh.textContainer.getLayoutParams();
        if (selected) {
          mSelectedVH = vh;
          v.setBackgroundColor(mSelectedItemBackgroundColor);
          vh.title.setTextColor(mSelectedItemTextColor);
          vh.when.setTextColor(mSelectedItemTextColor);
          vh.where.setTextColor(mSelectedItemTextColor);
          lp.setMargins(0, 0, 0, 0);
          vh.textContainer.setLayoutParams(lp);
        } else {
          lp.setMargins(0, 0, (int) mItemRightMargin, 0);
          vh.textContainer.setLayoutParams(lp);
        }
      }
    }

    if (DEBUGLOG) {
      Log.e(TAG, "getView " + position + " = " + getViewTitle(v));
    }
    return v;
  }