Example usage for android.widget LinearLayout setLayoutParams

List of usage examples for android.widget LinearLayout setLayoutParams

Introduction

In this page you can find the example usage for android.widget LinearLayout setLayoutParams.

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:run.ace.TabBar.java

View getCustomTabView(AppBarButton abb, Context themedContext) {
    float scaleFactor = Utils.getScaleFactor(themedContext);
    final int IMAGEHEIGHT = (int) (17 * scaleFactor);
    final int TEXTSIZE = 12;

    LinearLayout ll = new LinearLayout(themedContext);
    LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    llp.gravity = Gravity.CENTER_HORIZONTAL;
    ll.setLayoutParams(llp);
    ll.setOrientation(LinearLayout.VERTICAL);

    if (abb.icon != null) {
        ImageView iv = new ImageView(themedContext);
        LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                IMAGEHEIGHT);/* ww w .  j  a va 2s  .  c o m*/
        p.gravity = Gravity.CENTER_HORIZONTAL;
        p.topMargin = (int) (4 * scaleFactor);
        p.bottomMargin = (int) (3 * scaleFactor);
        iv.setLayoutParams(p);
        Bitmap bitmap = Utils.getBitmapAsset(themedContext, abb.icon.toString());
        iv.setImageDrawable(new android.graphics.drawable.BitmapDrawable(bitmap));
        ll.addView(iv);
    }

    TextView tv = new TextView(themedContext);
    LinearLayout.LayoutParams tvp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    tvp.gravity = Gravity.CENTER_HORIZONTAL;
    tv.setLayoutParams(tvp);
    tv.setTypeface(null, Typeface.BOLD);
    tv.setTextSize(TEXTSIZE);
    tv.setText(abb.label.toUpperCase());
    ll.addView(tv);

    return ll;
}

From source file:com.thevelopment.poc.Fragments.FirstFragment.java

private LinearLayout createInnerLinearLayout(ViewGroup parentView, int width, int height) {
    LinearLayout innerLinearLayout = screenBuilder.createVerticalLinearLayout(parentView);
    RelativeLayout.LayoutParams innerLinearLayoutParams = (RelativeLayout.LayoutParams) innerLinearLayout
            .getLayoutParams();//from  w  w  w.  ja v  a  2s  .c  o m
    innerLinearLayoutParams.setMargins(width / 20, height / 40, width / 20, height / 10);
    innerLinearLayout.setLayoutParams(innerLinearLayoutParams);
    return innerLinearLayout;
}

From source file:de.tobiasbielefeld.solitaire.ui.HighScores.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); //initialize stuff
    setContentView(R.layout.activity_high_scores);

    ActionBar actionBar = getSupportActionBar();
    layoutScores = (LinearLayout) findViewById(R.id.highScoresLinearLayout1); //load the layouts and textView
    textWonGames = (TextView) findViewById(R.id.highScoresTextViewGamesWon);
    textWinPercentage = (TextView) findViewById(R.id.highScoresTextViewWinPercentage);
    mAdView = (AdView) findViewById(R.id.adView2);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);/*from www . j  ava  2  s  .  c o  m*/

    if (actionBar != null) //set a nice back arrow in the actionBar
        actionBar.setDisplayHomeAsUpEnabled(true);

    loadStatistics();

    for (int i = 0; i < Scores.MAX_SAVED_SCORES; i++) { //for each entry in highScores, add a new view with it
        if (scores.get(i, 0) == 0) //if the score is zero, don't show it
            continue;

        final LinearLayout linearLayout2 = new LinearLayout(this); //new layout for the entry

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( //create new layout params
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);//
        params.setMargins(0, 0, 0, 10); //add some padding
        linearLayout2.setLayoutParams(params); //and apply them
        linearLayout2.setGravity(Gravity.CENTER); //set gravity
        linearLayout2.setOrientation(LinearLayout.HORIZONTAL); //also set orientation

        TextView textView = new TextView(this); //new textView for the score of the entry
        textView.setText(String.format(Locale.getDefault(), "%s. %s %s ", i + 1, getString( //add the score
                R.string.game_score), scores.get(i, 0)));
        textView.setTextSize(20); //and set text size

        TextView textView2 = new TextView(this); //new textView for the time of the entry
        textView2.setText(String.format(Locale.getDefault(), "%s %02d:%02d:%02d", //add it to the view
                getString(R.string.game_time), scores.get(i, 1) / 3600, (scores.get(i, 1) % 3600) / 60,
                (scores.get(i, 1) % 60)));
        textView2.setTextSize(20); //set size

        linearLayout2.addView(textView); //now add both textViews to the entry layout
        linearLayout2.addView(textView2);
        layoutScores.addView(linearLayout2); //and finally add the new entry layout to the scores layout
    }
}

From source file:eu.geopaparazzi.library.forms.views.GPictureView.java

/**
 * @param noteId                the id of the note this image belows to.
 * @param fragmentDetail        the fragment detail  to use.
 * @param attrs                 attributes.
 * @param requestCode           the code for starting the activity with result.
 * @param parentView            parent/*from  w w w .  j a va2  s .c  o  m*/
 * @param key                   key
 * @param value                 in case of pictures, the value are the ids of the image, semicolonseparated.
 * @param constraintDescription constraints
 */
public GPictureView(final long noteId, final FragmentDetail fragmentDetail, AttributeSet attrs,
        final int requestCode, LinearLayout parentView, String key, String value,
        String constraintDescription) {
    super(fragmentDetail.getActivity(), attrs);

    _value = value;

    final FragmentActivity activity = fragmentDetail.getActivity();
    LinearLayout textLayout = new LinearLayout(activity);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(10, 10, 10, 10);
    textLayout.setLayoutParams(layoutParams);
    textLayout.setOrientation(LinearLayout.VERTICAL);
    parentView.addView(textLayout);

    TextView textView = new TextView(activity);
    textView.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    textView.setPadding(2, 2, 2, 2);
    textView.setText(key.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription);
    textView.setTextColor(activity.getResources().getColor(R.color.formcolor));
    textLayout.addView(textView);

    final Button button = new Button(activity);
    button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    button.setPadding(15, 5, 15, 5);
    button.setText(R.string.take_picture);
    textLayout.addView(button);

    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
            double[] gpsLocation = PositionUtilities.getGpsLocationFromPreferences(preferences);

            String imageName = ImageUtilities.getCameraImageName(null);
            Intent cameraIntent = new Intent(activity, CameraActivity.class);
            cameraIntent.putExtra(LibraryConstants.PREFS_KEY_CAMERA_IMAGENAME, imageName);
            cameraIntent.putExtra(LibraryConstants.DATABASE_ID, noteId);
            if (gpsLocation != null) {
                cameraIntent.putExtra(LibraryConstants.LATITUDE, gpsLocation[1]);
                cameraIntent.putExtra(LibraryConstants.LONGITUDE, gpsLocation[0]);
                cameraIntent.putExtra(LibraryConstants.ELEVATION, gpsLocation[2]);
            }
            fragmentDetail.startActivityForResult(cameraIntent, requestCode);
        }
    });

    ScrollView scrollView = new ScrollView(activity);
    ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    scrollView.setLayoutParams(scrollLayoutParams);
    parentView.addView(scrollView);

    imageLayout = new LinearLayout(activity);
    LinearLayout.LayoutParams imageLayoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT);
    imageLayout.setLayoutParams(imageLayoutParams);
    imageLayout.setOrientation(LinearLayout.HORIZONTAL);
    scrollView.addView(imageLayout);

    try {
        refresh(activity);
    } catch (Exception e) {
        GPLog.error(this, null, e);
    }
}

From source file:paulscode.android.mupen64plusae.SplashActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get app data and user preferences
    mAppData = new AppData(this);
    mGlobalPrefs = new GlobalPrefs(this, mAppData);
    mGlobalPrefs.enforceLocale(this);
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);

    // Ensure that any missing preferences are populated with defaults (e.g. preference added to
    // new release)
    PreferenceManager.setDefaultValues(this, R.xml.preferences_audio, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_data, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_display, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_input, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_library, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_touchscreen, false);

    // Ensure that selected plugin names and other list preferences are valid
    // @formatter:off
    final Resources res = getResources();
    PrefUtil.validateListPreference(res, mPrefs, DISPLAY_ORIENTATION, R.string.displayOrientation_default,
            R.array.displayOrientation_values);
    PrefUtil.validateListPreference(res, mPrefs, DISPLAY_POSITION, R.string.displayPosition_default,
            R.array.displayPosition_values);
    PrefUtil.validateListPreference(res, mPrefs, DISPLAY_SCALING, R.string.displayScaling_default,
            R.array.displayScaling_values);
    PrefUtil.validateListPreference(res, mPrefs, VIDEO_HARDWARE_TYPE, R.string.videoHardwareType_default,
            R.array.videoHardwareType_values);
    PrefUtil.validateListPreference(res, mPrefs, AUDIO_PLUGIN, R.string.audioPlugin_default,
            R.array.audioPlugin_values);
    PrefUtil.validateListPreference(res, mPrefs, AUDIO_SDL_BUFFER_SIZE, R.string.audioSDLBufferSize_default,
            R.array.audioSDLBufferSize_values);
    PrefUtil.validateListPreference(res, mPrefs, AUDIO_SLES_BUFFER_SIZE, R.string.audioSLESBufferSize_default,
            R.array.audioSLESBufferSize_values);
    PrefUtil.validateListPreference(res, mPrefs, TOUCHSCREEN_AUTO_HOLD, R.string.touchscreenAutoHold_default,
            R.array.touchscreenAutoHold_values);
    PrefUtil.validateListPreference(res, mPrefs, NAVIGATION_MODE, R.string.navigationMode_default,
            R.array.navigationMode_values);

    if (!mPrefs.getBoolean("seen_survey", false)) {
        LinearLayout dialogLayout = new LinearLayout(this);
        dialogLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        dialogLayout.setOrientation(LinearLayout.VERTICAL);
        TextView message = new TextView(this);
        message.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        message.setText("We have recently changed our icon and we want your feedback!\n\n"
                + "Please take a few moments to fill out this feedback form so we can make improvements. "
                + "You will need a Google account to fill out this form. This is so we don't have duplicates.");
        message.setPadding(16, 16, 16, 16);
        dialogLayout.addView(message);/* www  .  j av a 2s. co m*/
        ImageView icon = new ImageView(this);
        icon.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        icon.setAdjustViewBounds(true);
        icon.setPadding(16, 16, 16, 16);
        icon.setImageResource(R.drawable.ic_playstore_ouya);
        dialogLayout.addView(icon);
        AlertDialog dialog = new AlertDialog.Builder().setTitle("We want your feedback!").setView(iconLayout)
                .setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(
                                "https://docs.google.com/forms/d/1F2stkHvb0Rx5vfmaz50OtTfT73XjHK2GEXZj9a_x-yw/viewform"));
                        SplashActivity.this.startActivity(i);
                    }
                }).setNegativeButton(getString(android.R.string.cancel), null).create();
        mPrefs.edit().putBoolean("seen_survey", true).apply();
        dialog.show();
    }
    //Check for invalid data path
    String dataPathString = mPrefs.getString(DATA_PATH, null);

    if (dataPathString == null || dataPathString.isEmpty()
            || dataPathString.contains(res.getString(R.string.pathGameSaves_default))) {
        String defValue = res.getString(R.string.pathGameSaves_default);
        String newDefValue = PathPreference.validate(defValue);

        mPrefs.edit().putString(DATA_PATH, newDefValue).commit();
    }

    // @formatter:on

    // Refresh the preference data wrapper
    mGlobalPrefs = new GlobalPrefs(this, mAppData);

    // Make sure custom skin directory exist
    new File(mGlobalPrefs.touchscreenCustomSkinsDir).mkdirs();

    // Initialize the OUYA interface if running on OUYA
    if (AppData.IS_OUYA_HARDWARE)
        OuyaFacade.getInstance().init(this, DEVELOPER_ID);

    // Initialize the toast/status bar notifier
    Notifier.initialize(this);

    // Don't let the activity sleep in the middle of extraction
    getWindow().setFlags(LayoutParams.FLAG_KEEP_SCREEN_ON, LayoutParams.FLAG_KEEP_SCREEN_ON);

    // Lay out the content
    setContentView(R.layout.splash_activity);
    mTextView = (TextView) findViewById(R.id.mainText);

    if (mGlobalPrefs.isBigScreenMode) {
        final ImageView splash = (ImageView) findViewById(R.id.mainImage);
        splash.setImageResource(R.drawable.publisherlogo_ouya);
    }

    requestPermissions();

    // Popup a warning if the installation appears to be corrupt
    if (!mAppData.isValidInstallation()) {
        Popups.showInvalidInstall(this);
    }
}

From source file:net.pocketmagic.android.eventinjector.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(LT, "App created.");
    Events.intEnableDebug(1);/*w ww  . ja  va  2s  .c o  m*/
    // disable the titlebar
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    // create a basic user interface
    LinearLayout panel = new LinearLayout(this);
    panel.setOrientation(LinearLayout.VERTICAL);
    setContentView(panel);

    EditText v = new EditText(this);
    v.setId(idTextView);
    v.setOnClickListener(this);
    panel.addView(v);

    // --
    Button b = new Button(this);
    b.setText("Scan Input Devs");
    b.setId(idButScan);
    b.setOnClickListener(this);
    panel.addView(b);

    // put list in a scroll view
    LinearLayout listLayout = new LinearLayout(this);
    listLayout.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
    m_lvDevices = new ListView(this);
    LayoutParams lvLayoutParam = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    m_lvDevices.setLayoutParams(lvLayoutParam);
    m_lvDevices.setId(idLVDevices);
    m_lvDevices.setDividerHeight(0);
    m_lvDevices.setFadingEdgeLength(0);
    m_lvDevices.setCacheColorHint(0);
    m_lvDevices.setAdapter(null);

    listLayout.addView(m_lvDevices);
    panel.addView(listLayout);
    // --
    LinearLayout panelH = new LinearLayout(this);
    panelH.setOrientation(LinearLayout.HORIZONTAL);
    panel.addView(panelH);
    // --
    m_selDevSpinner = new Spinner(this);
    m_selDevSpinner.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    m_selDevSpinner.setId(idSelSpin);
    m_selDevSpinner.setOnItemSelectedListener((OnItemSelectedListener) this);
    panelH.addView(m_selDevSpinner);
    // -- simulate key event
    b = new Button(this);
    b.setText(">Key");
    b.setId(idButInjectKey);
    b.setOnClickListener(this);
    panelH.addView(b);
    // -- simulate touch event
    b = new Button(this);
    b.setText(">Tch");
    b.setId(idButInjectTouch);
    b.setOnClickListener(this);
    panelH.addView(b);
    // --
    m_tvMonitor = new TextView(this);
    m_tvMonitor.setText("Event Monitor stopped.");
    panel.addView(m_tvMonitor);
    // --
    panelH = new LinearLayout(this);
    panelH.setOrientation(LinearLayout.HORIZONTAL);
    panel.addView(panelH);
    // --
    b = new Button(this);
    b.setText("Monitor Start");
    b.setId(idButMonitorStart);
    b.setOnClickListener(this);
    panelH.addView(b);
    // --
    b = new Button(this);
    b.setText("Monitor Stop");
    b.setId(idButMonitorStop);
    b.setOnClickListener(this);
    panelH.addView(b);
    // -- simulate test event
    b = new Button(this);
    b.setText(">Test");
    b.setId(idButTest);
    b.setOnClickListener(this);
    panelH.addView(b);
}

From source file:com.thevelopment.poc.Fragments.FirstFragment.java

public Spinner createTypeOfInspectionField(ViewGroup parentView, int width) {
    // CREATE TYPE OF INSPECTION LINEAR LAYOUT
    LinearLayout typeOfInspectionLinearLayout = screenBuilder.createVerticalLinearLayout(parentView,
            2 * width / 5, LinearLayout.LayoutParams.WRAP_CONTENT);
    LinearLayout.LayoutParams typeOfInspectionParams = (LinearLayout.LayoutParams) typeOfInspectionLinearLayout
            .getLayoutParams();// www.  ja v  a 2  s. c  om
    typeOfInspectionParams.rightMargin = width / 10;
    typeOfInspectionLinearLayout.setLayoutParams(typeOfInspectionParams);

    // CREATE TYPE OF INSPECTION TEXT VIEW
    screenBuilder.createTextView(typeOfInspectionLinearLayout, "Tipo de Inspecao", 14);

    // CREATE TYPE OF INSPECTION SPINNER
    final Spinner typeSpinner = screenBuilder.createSpinner(typeOfInspectionLinearLayout,
            Arrays.asList(getResources().getStringArray(R.array.type_array)));

    return typeSpinner;

}

From source file:jfabrix101.lib.fragmentActivity.AbstractFragmentActivityController.java

/**
 * Crea un layout verticale utilizzando il solo fragment di sinistra (la lista)
 *//*from w ww.j  ava  2s  .co  m*/
@SuppressWarnings("all")
protected View makeLeftPortraitLayout(LayoutInflater inflater) {
    if (getLayoutResourceId() > 0) {
        View v = LayoutInflater.from(this).inflate(getLayoutResourceId(), null);
        View rightFragment = v.findViewById(getRightFragmentId());
        if (rightFragment != null) {
            rightFragment.setVisibility(View.GONE);
        }
        mVisualizationMode = VisualizationMode.PORTRAIT_ONLY_LEFT;
        return v;
    } else {
        LinearLayout layout = new LinearLayout(this);

        layout.setPadding(10, 10, 10, 10);
        layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        layout.setOrientation(LinearLayout.VERTICAL);

        FrameLayout leftFrame = new FrameLayout(this);
        leftFrame.setId(getLeftFragmentId());
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.FILL_PARENT);
        leftFrame.setLayoutParams(lp);

        layout.addView(leftFrame);
        mVisualizationMode = VisualizationMode.PORTRAIT_ONLY_LEFT;
        return layout;
    }
}

From source file:jfabrix101.lib.fragmentActivity.AbstractFragmentActivityController.java

/**
 * Crea un layout in landscape utilizzando due fragment di peso proporzionale
 * Per cambiare le dimensioni dei pesi effettuare l'override dei 
 * metodi <code>getLeftFragmentSize</code> e <code>getRightFragmentSize</code> 
 */// ww  w  . j  av  a2  s .  c om
@SuppressWarnings("all")
protected View makeLandscapeLayout(LayoutInflater inflater) {
    if (getLayoutResourceId() > 0) {
        View v = inflater.inflate(getLayoutResourceId(), null);
        mVisualizationMode = VisualizationMode.LANDSCAPE;
        return v;
    } else {
        LinearLayout layout = new LinearLayout(this);
        layout.setPadding(10, 10, 10, 10);
        layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        layout.setOrientation(LinearLayout.HORIZONTAL);

        FrameLayout leftFrame = new FrameLayout(this);
        leftFrame.setId(getLeftFragmentId());
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LayoutParams.FILL_PARENT,
                getLeftFragmentWeigth());
        leftFrame.setLayoutParams(lp);

        FrameLayout rightFrame = new FrameLayout(this);
        rightFrame.setId(getRightFragmentId());
        lp = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, getRightFragmentWeigth());
        rightFrame.setLayoutParams(lp);

        layout.addView(leftFrame);
        layout.addView(rightFrame);
        mVisualizationMode = VisualizationMode.LANDSCAPE;
        return layout;
    }

}

From source file:nit.contact.views.PagerSlidingTabStrip.java

private void addTabView(int position) {
    LinearLayout view = new LinearLayout(getContext());
    view.setOrientation(LinearLayout.VERTICAL);
    view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    view.setGravity(Gravity.CENTER);//from   w  ww . j ava 2 s  .  c o m
    view.setPadding(tabPadding, indicatorHeight, tabPadding, indicatorHeight);

    View tab = ((IconTabProvider) mPager.getAdapter()).getView(position);
    view.addView(tab);
    addTab(position, view);
}