Example usage for android.widget LinearLayout LinearLayout

List of usage examples for android.widget LinearLayout LinearLayout

Introduction

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

Prototype

public LinearLayout(Context context) 

Source Link

Usage

From source file:com.github.johnpersano.supertoasts.demo.views.TabStrip.java

public TabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setFillViewport(true);/*www  .j  a  v  a2s . c  om*/
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);
    indicatorPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, indicatorPadding, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);

    a.recycle();

    a = context.obtainStyledAttributes(attrs, R.styleable.TabStrip);

    indicatorColor = a.getColor(R.styleable.TabStrip_TabStripIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.TabStrip_TabStripUnderlineColor, underlineColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.TabStrip_TabStripIndicatorHeight, indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.TabStrip_TabStripUnderlineHeight, underlineHeight);
    tabPadding = a.getDimensionPixelSize(R.styleable.TabStrip_TabStripTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.TabStrip_TabStripTabBackground, tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.TabStrip_TabStripShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.TabStrip_TabStripScrollOffset, scrollOffset);
    tabSwitch = a.getBoolean(R.styleable.TabStrip_TabStripTabSwitch, tabSwitch);
    tabTextColor = a.getColor(R.styleable.TabStrip_TabStripActivateTextColor, tabTextColor);
    tabDeactivateTextColor = a.getColor(R.styleable.TabStrip_TabStripDeactivateTextColor,
            tabDeactivateTextColor);
    indicatorPadding = a.getDimensionPixelSize(R.styleable.TabStrip_TabStripIndicatorPadding, indicatorPadding);

    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:org.quantumbadger.redreader.activities.AlbumListingActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    PrefsUtility.applyTheme(this);

    OptionsMenuUtility.fixActionBar(AlbumListingActivity.this, getString(R.string.imgur_album));

    if (getActionBar() != null) {
        getActionBar().setHomeButtonEnabled(true);
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }/*from  ww  w .  j  a  v  a2  s. c o  m*/

    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    final boolean solidblack = PrefsUtility.appearance_solidblack(this, sharedPreferences)
            && PrefsUtility.appearance_theme(this, sharedPreferences) == PrefsUtility.AppearanceTheme.NIGHT;

    if (solidblack)
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK));

    final Intent intent = getIntent();

    mUrl = intent.getDataString();

    if (mUrl == null) {
        finish();
        return;
    }

    final Matcher matchImgur = LinkHandler.imgurAlbumPattern.matcher(mUrl);
    final String albumId;

    if (matchImgur.find()) {
        albumId = matchImgur.group(2);
    } else {
        Log.e("AlbumListingActivity", "URL match failed");
        revertToWeb();
        return;
    }

    Log.i("AlbumListingActivity", "Loading URL " + mUrl + ", album id " + albumId);

    final ProgressBar progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
    progressBar.setIndeterminate(true);

    final LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(progressBar);

    ImgurAPI.getAlbumInfo(this, albumId, Constants.Priority.IMAGE_VIEW, 0, new GetAlbumInfoListener() {

        @Override
        public void onFailure(final RequestFailureType type, final Throwable t, final StatusLine status,
                final String readableMessage) {
            Log.e("AlbumListingActivity", "getAlbumInfo call failed: " + type);

            if (status != null)
                Log.e("AlbumListingActivity", "status was: " + status.toString());
            if (t != null)
                Log.e("AlbumListingActivity", "exception was: ", t);

            // It might be a single image, not an album

            if (status == null) {
                revertToWeb();
                return;
            }

            ImgurAPI.getImageInfo(AlbumListingActivity.this, albumId, Constants.Priority.IMAGE_VIEW, 0,
                    new GetImageInfoListener() {
                        @Override
                        public void onFailure(final RequestFailureType type, final Throwable t,
                                final StatusLine status, final String readableMessage) {
                            Log.e("AlbumListingActivity", "Image info request also failed: " + type);
                            revertToWeb();
                        }

                        @Override
                        public void onSuccess(final ImageInfo info) {
                            Log.i("AlbumListingActivity", "Link was actually an image.");
                            LinkHandler.onLinkClicked(AlbumListingActivity.this, info.urlOriginal);
                            finish();
                        }

                        @Override
                        public void onNotAnImage() {
                            Log.i("AlbumListingActivity", "Not an image either");
                            revertToWeb();
                        }
                    });
        }

        @Override
        public void onSuccess(final ImgurAPI.AlbumInfo info) {
            Log.i("AlbumListingActivity", "Got album, " + info.images.size() + " image(s)");

            AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                @Override
                public void run() {

                    if (info.title != null && !info.title.trim().isEmpty()) {
                        OptionsMenuUtility.fixActionBar(AlbumListingActivity.this,
                                getString(R.string.imgur_album) + ": " + info.title);
                    }

                    layout.removeAllViews();

                    final ListView listView = new ListView(AlbumListingActivity.this);
                    listView.setAdapter(new AlbumAdapter(info));
                    layout.addView(listView);

                    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(final AdapterView<?> parent, final View view,
                                final int position, final long id) {

                            LinkHandler.onLinkClicked(AlbumListingActivity.this,
                                    info.images.get(position).urlOriginal, false, null, info, position);
                        }
                    });
                }
            });
        }
    });

    setContentView(layout);
}

From source file:br.org.funcate.dynamicforms.views.GSketchView.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 ww. j a va2s  .  co  m*/
 * @param label                 label
 * @param value                 value
 * @param constraintDescription constraints
 */
public GSketchView(final long noteId, final FragmentDetail fragmentDetail, AttributeSet attrs,
        final int requestCode, LinearLayout parentView, String label, String value,
        String constraintDescription) {
    super(fragmentDetail.getActivity(), attrs);
    this.noteId = noteId;

    _value = value;

    final FragmentActivity activity = fragmentDetail.getActivity();
    LinearLayout textLayout = new LinearLayout(activity);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_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.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    textView.setPadding(2, 2, 2, 2);
    textView.setText(label.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.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    button.setPadding(15, 5, 15, 5);
    button.setText(R.string.draw_sketch);
    textLayout.addView(button);

    button.setOnClickListener(new View.OnClickListener() {

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

                Date currentDate = new Date();
                String sketchImageName = ImageUtilities.getSketchImageName(currentDate);

                File tempDir = ResourcesManager.getInstance(getContext()).getTempDir();
                File sketchFile = new File(tempDir, sketchImageName);
                /*
                 * open markers for new sketch
                 */
                MarkersUtilities.launch(fragmentDetail, sketchFile, gpsLocation, requestCode);
            } catch (Exception e) {
                //GPLog.error(this, null, e);
                Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }
    });

    ScrollView scrollView = new ScrollView(activity);
    ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT, 150);
    scrollView.setLayoutParams(scrollLayoutParams);
    parentView.addView(scrollView);

    imageLayout = new LinearLayout(activity);
    LinearLayout.LayoutParams imageLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT);
    imageLayout.setLayoutParams(imageLayoutParams);
    // imageLayout.setMinimumHeight(200);
    imageLayout.setOrientation(LinearLayout.HORIZONTAL);
    scrollView.addView(imageLayout);
    // scrollView.setFillViewport(true);

    try {
        refresh(activity);
    } catch (Exception e) {
        //GPLog.error(this, null, e);
        Toast.makeText(this.getContext(), e.getMessage(), Toast.LENGTH_LONG).show();
    }
}

From source file:com.fibrobook.viewpager.custom.CardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    LayoutParams params = new LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
            android.view.ViewGroup.LayoutParams.MATCH_PARENT);

    FrameLayout fl = new FrameLayout(getActivity());
    fl.setLayoutParams(params);//from   w  w  w .j  av  a 2 s. c  o m

    final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            getResources().getDisplayMetrics());

    LinearLayout l = new LinearLayout(getActivity());
    params.setMargins(margin, margin, margin, margin);
    l.setLayoutParams(params);
    l.setGravity(Gravity.CENTER);
    l.setBackgroundResource(R.drawable.background_card);

    switch (position) {

    case 0:
        symphtomsView(l);
        break;

    case 1:
        dayView(l);
        break;

    }

    fl.addView(l);
    return fl;
}

From source file:com.andrew.apollo.menu.PlaylistDialog.java

@Override
public void onCreate(Bundle icicle) {

    super.onCreate(icicle);
    setContentView(new LinearLayout(this));

    action = getIntent().getAction();/*w w w. j a  va2s  .c o m*/

    mRenameId = icicle != null ? icicle.getLong(INTENT_KEY_RENAME)
            : getIntent().getLongExtra(INTENT_KEY_RENAME, -1);
    mList = icicle != null ? icicle.getLongArray(INTENT_PLAYLIST_LIST)
            : getIntent().getLongArrayExtra(INTENT_PLAYLIST_LIST);
    if (INTENT_RENAME_PLAYLIST.equals(action)) {
        mOriginalName = nameForId(mRenameId);
        mDefaultName = icicle != null ? icicle.getString(INTENT_KEY_DEFAULT_NAME) : mOriginalName;
    } else if (INTENT_CREATE_PLAYLIST.equals(action)) {
        mDefaultName = icicle != null ? icicle.getString(INTENT_KEY_DEFAULT_NAME) : makePlaylistName();
        mOriginalName = mDefaultName;
    }

    DisplayMetrics dm = new DisplayMetrics();
    dm = getResources().getDisplayMetrics();

    mPlaylistDialog = new AlertDialog.Builder(this).create();
    mPlaylistDialog.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    if (action != null && mRenameId >= 0 && mOriginalName != null || mDefaultName != null) {

        mPlaylist = new EditText(this);
        mPlaylist.setSingleLine(true);
        mPlaylist.setText(mDefaultName);
        mPlaylist.setSelection(mDefaultName.length());
        mPlaylist.addTextChangedListener(this);

        mPlaylistDialog.setIcon(android.R.drawable.ic_dialog_info);
        String promptformat;
        String prompt = "";
        if (INTENT_RENAME_PLAYLIST.equals(action)) {
            promptformat = getString(R.string.rename_playlist);
            prompt = String.format(promptformat, mOriginalName, mDefaultName);
        } else if (INTENT_CREATE_PLAYLIST.equals(action)) {
            promptformat = getString(R.string.new_playlist);
            prompt = String.format(promptformat, mDefaultName);
        }

        mPlaylistDialog.setTitle(prompt);
        mPlaylistDialog.setView(mPlaylist, (int) (8 * dm.density), (int) (8 * dm.density),
                (int) (8 * dm.density), (int) (4 * dm.density));
        if (INTENT_RENAME_PLAYLIST.equals(action)) {
            mPlaylistDialog.setButton(Dialog.BUTTON_POSITIVE, getString(R.string.save),
                    mRenamePlaylistListener);
            mPlaylistDialog.setOnShowListener(this);
        } else if (INTENT_CREATE_PLAYLIST.equals(action)) {
            mPlaylistDialog.setButton(Dialog.BUTTON_POSITIVE, getString(R.string.save),
                    mCreatePlaylistListener);
        }
        mPlaylistDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.cancel),
                new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        finish();
                    }
                });
        mPlaylistDialog.setOnCancelListener(this);
        mPlaylistDialog.show();
    } else {
        Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show();
        finish();
    }

}

From source file:by.istin.android.xcore.inherited.fragment.AdapterViewFragment.java

/**
 * Provide default implementation to return a simple list view.  Subclasses
 * can override to replace with their own layout.  If doing so, the
 * returned view hierarchy <em>must</em> have a ListView whose id
 * is {@link android.R.id#list android.R.id.list} and can optionally
 * have a sibling view id {@link android.R.id#empty android.R.id.empty}
 * that is to be shown when the list is empty.
 * /*from   w ww. j  a v a  2 s . c  o  m*/
 * <p>If you are overriding this method with your own custom content,
 * consider including the standard layout {@link android.R.layout#list_content}
 * in your layout file, so that you continue to retain all of the standard
 * behavior of ListFragment.  In particular, this is currently the only
 * way to have the built-in indeterminant progress state be shown.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);

    TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    AdapterView<?> adapterView = createDefaultAbstractView();

    adapterView.setId(android.R.id.list);
    if (adapterView instanceof ListView) {
        ((ListView) adapterView).setDrawSelectorOnTop(false);
    }
    lframe.addView(adapterView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    return root;
}

From source file:ch.arnab.simplelauncher.GridFragment.java

/**
 * Provide default implementation to return a simple grid view.  Subclasses
 * can override to replace with their own layout.  If doing so, the
 * returned view hierarchy <em>must</em> have a GridView whose id
 * is {@link android.R.id#list android.R.id.list} and can optionally
 * have a sibling view id {@link android.R.id#empty android.R.id.empty}
 * that is to be shown when the grid is empty.
 *
 * <p>If you are overriding this method with your own custom content,
 * consider including the standard layout {@link android.R.layout#list_content}
 * in your layout file, so that you continue to retain all of the standard
 * behavior of ListFragment.  In particular, this is currently the only
 * way to have the built-in indeterminant progress state be shown.
 *//*from  www  .  ja v a2 s.c  o  m*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);

    TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    GridView lv = new GridView(getActivity());
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    lv.setColumnWidth(convertDpToPixels(60, getActivity()));
    lv.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
    lv.setNumColumns(GridView.AUTO_FIT);
    lv.setHorizontalSpacing(convertDpToPixels(20, getActivity()));
    lv.setVerticalSpacing(convertDpToPixels(20, getActivity()));
    lv.setSmoothScrollbarEnabled(true);

    // disable overscroll
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        lv.setOverScrollMode(ListView.OVER_SCROLL_NEVER);
    }

    lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    return root;
}

From source file:com.ckdroid.ilauncher.ShowGridFragment.java

/**
 * Provide default implementation to return a simple grid view.  Subclasses
 * can override to replace with their own layout.  If doing so, the
 * returned view hierarchy <em>must</em> have a GridView whose id
 * is {@link android.R.id#list android.R.id.list} and can optionally
 * have a sibling view id {@link android.R.id#empty android.R.id.empty}
 * that is to be shown when the grid is empty.
 * <p/>/*from   ww  w. ja v  a2  s  . com*/
 * <p>If you are overriding this method with your own custom content,
 * consider including the standard layout {@link android.R.layout#list_content}
 * in your layout file, so that you continue to retain all of the standard
 * behavior of ListFragment.  In particular, this is currently the only
 * way to have the built-in indeterminant progress state be shown.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);

    TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    GridView lv = new GridView(getActivity());
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    lv.setColumnWidth(convertDpToPixels(80, getActivity()));
    lv.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
    lv.setNumColumns(GridView.AUTO_FIT);
    lv.setNumColumns(4);
    lv.setHorizontalSpacing(convertDpToPixels(10, getActivity()));
    lv.setVerticalSpacing(convertDpToPixels(10, getActivity()));
    lv.setSmoothScrollbarEnabled(true);

    // disable overscroll
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        lv.setOverScrollMode(ListView.OVER_SCROLL_NEVER);
    }

    lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    return root;
}

From source file:com.ckdroid.ilauncher.AllGridFragment.java

/**
 * Provide default implementation to return a simple grid view.  Subclasses
 * can override to replace with their own layout.  If doing so, the
 * returned view hierarchy <em>must</em> have a GridView whose id
 * is {@link android.R.id#list android.R.id.list} and can optionally
 * have a sibling view id {@link android.R.id#empty android.R.id.empty}
 * that is to be shown when the grid is empty.
 * <p/>//from  w w  w .jav  a2  s .co m
 * <p>If you are overriding this method with your own custom content,
 * consider including the standard layout {@link android.R.layout#list_content}
 * in your layout file, so that you continue to retain all of the standard
 * behavior of ListFragment.  In particular, this is currently the only
 * way to have the built-in indeterminant progress state be shown.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    FrameLayout lframe = new FrameLayout(context);
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);

    TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    GridView lv = new GridView(getActivity());
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    lv.setColumnWidth(convertDpToPixels(60, getActivity()));
    lv.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
    lv.setNumColumns(GridView.AUTO_FIT);
    lv.setHorizontalSpacing(convertDpToPixels(20, getActivity()));
    lv.setVerticalSpacing(convertDpToPixels(20, getActivity()));
    lv.setSmoothScrollbarEnabled(true);

    // disable overscroll
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        lv.setOverScrollMode(ListView.OVER_SCROLL_NEVER);
    }

    lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    root.setPadding(24, 30, 24, 30);

    root.setBackgroundColor(getResources().getColor(R.color.bg_white));

    return root;
}

From source file:com.example.twopane.GridFragment0.java

/**
 * Provide default implementation to return a simple grid view. Subclasses
 * can override to replace with their own layout. If doing so, the returned
 * view hierarchy <em>must</em> have a GridView whose id is
 * {@link android.R.id#list android.R.id.list} and can optionally have a
 * sibling view id {@link android.R.id#empty android.R.id.empty} that is to
 * be shown when the list is empty./* w ww . j av a  2 s . c  om*/
 * 
 * <p>
 * If you are overriding this method with your own custom content, consider
 * including the standard layout {@link android.R.layout#list_content} in
 * your layout file, so that you continue to retain all of the standard
 * behavior of GridFragment. In particular, this is currently the only way
 * to have the built-in indeterminant progress state be shown.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final Context context = getActivity();

    //return inflater.inflate(android.R.layout.list_content,container, false);

    FrameLayout root = new FrameLayout(context);

    // ------------------------------------------------------------------

    LinearLayout pframe = new LinearLayout(context);
    pframe.setId(INTERNAL_PROGRESS_CONTAINER_ID);
    pframe.setOrientation(LinearLayout.VERTICAL);
    pframe.setVisibility(View.GONE);
    pframe.setGravity(Gravity.CENTER);

    ProgressBar progress = new ProgressBar(context, null, android.R.attr.progressBarStyleLarge);
    pframe.addView(progress, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    root.addView(pframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    // ------------------------------------------------------------------

    FrameLayout gframe = new FrameLayout(context);
    gframe.setId(INTERNAL_GRID_CONTAINER_ID);

    TextView tv = new TextView(context);
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    gframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    GridView gv = new GridView(context);
    gv.setId(android.R.id.list);
    gv.setDrawSelectorOnTop(false);
    gframe.addView(gv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    root.addView(gframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    // ------------------------------------------------------------------

    root.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    return root;
}