Example usage for android.widget GridLayout HORIZONTAL

List of usage examples for android.widget GridLayout HORIZONTAL

Introduction

In this page you can find the example usage for android.widget GridLayout HORIZONTAL.

Prototype

int HORIZONTAL

To view the source code for android.widget GridLayout HORIZONTAL.

Click Source Link

Document

The horizontal orientation.

Usage

From source file:com.gelakinetic.mtgfam.fragments.LifeCounterFragment.java

/**
 * Updates the display mode based on the current value of mDisplayMode. This updates the GridLayout's parameters
 * and draws the player's views in the fragment. It also shows and hides buttons and views relating to
 * commander mode./*from w w  w .  j  a  v a2  s. c  o m*/
 */
public void changeDisplayMode(boolean shouldDefaultLives) {
    /* update the preference */
    PreferenceAdapter.setDisplayMode(getContext(), String.valueOf(mDisplayMode));

    mGridLayout.removeAllViews();

    if (getActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        switch (mDisplayMode) {
        case DISPLAY_NORMAL:
            mGridLayout.setOrientation(GridLayout.HORIZONTAL);
            mGridLayout.setColumnCount(1);
            mGridLayout.setRowCount(GridLayout.UNDEFINED);
            break;
        case DISPLAY_COMPACT:
            mGridLayout.setOrientation(GridLayout.HORIZONTAL);
            mGridLayout.setColumnCount(2);
            mGridLayout.setRowCount(GridLayout.UNDEFINED);
            break;
        case DISPLAY_COMMANDER:
            mGridLayout.setOrientation(GridLayout.HORIZONTAL);
            mGridLayout.setColumnCount(2);
            mGridLayout.setRowCount(GridLayout.UNDEFINED);
            break;
        }
    } else {
        switch (mDisplayMode) {
        case DISPLAY_NORMAL:
            mGridLayout.setOrientation(GridLayout.HORIZONTAL);
            mGridLayout.setColumnCount(GridLayout.UNDEFINED);
            mGridLayout.setRowCount(1);
            break;
        case DISPLAY_COMPACT:
            mGridLayout.setOrientation(GridLayout.HORIZONTAL);
            mGridLayout.setColumnCount(GridLayout.UNDEFINED);
            mGridLayout.setRowCount(1);
            break;
        case DISPLAY_COMMANDER:
            mGridLayout.setOrientation(GridLayout.VERTICAL);
            mGridLayout.setColumnCount(GridLayout.UNDEFINED);
            if (mListSizeHeight != -1) {
                float height = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48,
                        getActivity().getResources().getDisplayMetrics());
                mGridLayout.setRowCount((int) (mListSizeHeight / height));
            } else {
                mGridLayout.setRowCount(GridLayout.UNDEFINED);
            }
            break;
        }
    }

    boolean areLivesDefault = true;
    for (LcPlayer player : mPlayers) {
        /* Only reset a player's default life / life if that player is unaltered and doesn't have a noticeably
         * custom default life */
        if (!(player.mLifeHistory.size() == 0 && player.mPoisonHistory.size() == 0
                && player.mLife == player.mDefaultLifeTotal && (player.mDefaultLifeTotal == DEFAULT_LIFE
                        || player.mDefaultLifeTotal == DEFAULT_LIFE_COMMANDER))) {
            areLivesDefault = false;
        }
    }

    if (areLivesDefault && shouldDefaultLives) {
        for (LcPlayer player : mPlayers) {
            player.mDefaultLifeTotal = getDefaultLife();
            player.mLife = player.mDefaultLifeTotal;
        }
    }

    for (LcPlayer player : mPlayers) {
        /* Draw the player's view */
        addPlayerView(player);
    }

    if (mDisplayMode == DISPLAY_COMMANDER) {
        mCommanderButton.setVisibility(View.VISIBLE);
        mCommanderPlayerView.setVisibility(View.VISIBLE);
        mCommanderPlayerView.removeAllViews();
        if (mPlayers.size() > 0 && null != mPlayers.get(0).mView) {
            mCommanderPlayerView.addView(mPlayers.get(0).mView);
            mPlayers.get(0).setSize(mListSizeWidth, mListSizeHeight, mDisplayMode, getActivity().getResources()
                    .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
        }
    } else {
        mCommanderPlayerView.setVisibility(View.GONE);
        mCommanderButton.setVisibility(View.GONE);
        if (mStatDisplaying == STAT_COMMANDER) {
            setStatDisplaying(STAT_LIFE);
        }
    }
}

From source file:com.retroteam.studio.retrostudio.EditorLandscape.java

/**
 * Create all the views associated with a track.
 * @param waveDrawableID/*from   w w w.j a va 2s  .com*/
 * @param projectLoad
 * @return
 */

private ImageView addTrack(int waveDrawableID, boolean projectLoad) {
    //add the track with the measure adder to the view
    //get layout
    LinearLayout track_layout = (LinearLayout) findViewById(R.id.track_layout);

    //create track container
    HorizontalScrollView track_container = new HorizontalScrollView(getApplicationContext());
    track_container.setLayoutParams(new HorizontalScrollView.LayoutParams(
            HorizontalScrollView.LayoutParams.MATCH_PARENT, displaysize.y / 4));
    track_container.setBackground(getResources().getDrawable(R.color.track_container_bg));

    //create grid layout
    GridLayout track_grid = new GridLayout(getApplicationContext());
    track_grid.setColumnCount(100);
    track_grid.setRowCount(1);
    track_grid.setOrientation(GridLayout.HORIZONTAL);
    track_grid.setId(R.id.track_grid);

    //create linear layout for track id and wave
    LinearLayout track_identifier = new LinearLayout(getApplicationContext());
    track_identifier.setLayoutParams(new LinearLayout.LayoutParams(displaysize.x / 14, displaysize.y / 4));
    track_identifier.setOrientation(LinearLayout.VERTICAL);
    track_identifier.setBackgroundColor(getResources().getColor(R.color.black_overlay));

    //create textview for linear layout
    TextView track_num = new TextView(getApplicationContext());
    track_num.setText("1");
    track_num.setTextSize(45);
    track_num.setGravity(Gravity.CENTER | Gravity.CENTER_VERTICAL);

    //create imageview for linear layout
    ImageView track_type = new ImageView(getApplicationContext());
    track_type.setImageResource(waveDrawableID);
    track_type.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT));

    //create "add measure" for grid layout
    ImageView add_measure = new ImageView(getApplicationContext());
    add_measure.setImageResource(R.drawable.measure_new);
    add_measure.setLayoutParams(new LinearLayout.LayoutParams((int) (displaysize.x / 3.32),
            LinearLayout.LayoutParams.MATCH_PARENT));
    if (projectLoad) {
        add_measure.setTag(R.id.TAG_ROW, trackReloadCounter);
        add_measure.setId(trackReloadCounter + 4200);
    } else {
        add_measure.setTag(R.id.TAG_ROW, theproject.size() - 1);
        add_measure.setId(theproject.size() - 1 + 4200);
    }

    add_measure.setTag(R.id.TAG_COLUMN, 0);
    add_measure.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            addMeasure(v, false);

        }
    });

    track_identifier.addView(track_num);
    if (projectLoad) {
        track_num.setText(Integer.toString(trackReloadCounter + 1));
        trackReloadCounter += 1;
    } else {
        track_num.setText(Integer.toString(theproject.size()));
    }
    track_num.setTextSize(45);
    track_identifier.addView(track_type);

    track_grid.addView(track_identifier);
    track_grid.addView(add_measure);

    track_container.addView(track_grid);

    track_layout.addView(track_container);

    return add_measure;

}