Example usage for android.widget FrameLayout setLayoutParams

List of usage examples for android.widget FrameLayout setLayoutParams

Introduction

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

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:com.heneryh.aquanotes.ui.SearchActivity.java

/**
 * Build and add "vendors" tab.//from   w ww  .  ja v a 2 s  .co  m
 */
private void setupVendorsTab() {
    // TODO: this is very inefficient and messy, clean it up
    FrameLayout fragmentContainer = new FrameLayout(this);
    fragmentContainer.setId(R.id.fragment_controllers);
    fragmentContainer.setLayoutParams(
            new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
    ((ViewGroup) findViewById(android.R.id.tabcontent)).addView(fragmentContainer);

    final FragmentManager fm = getSupportFragmentManager();
    mVendorsFragment = (DbMaintControllersFragment) fm.findFragmentByTag("vendors");
    if (mVendorsFragment == null) {
        mVendorsFragment = new DbMaintControllersFragment();
        mVendorsFragment.setArguments(getVendorsFragmentArguments());
        fm.beginTransaction().add(R.id.fragment_controllers, mVendorsFragment, "vendors").commit();
    } else {
        mVendorsFragment.reloadFromArguments(getVendorsFragmentArguments());
    }

    // Vendors content comes from reused activity
    mTabHost.addTab(mTabHost.newTabSpec(TAG_VENDORS).setIndicator(buildIndicator(R.string.db_maint_controllers))
            .setContent(R.id.fragment_controllers));
}

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);

    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);//from w ww  .  java2 s  . c o  m
    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.chrslee.csgopedia.app.CardFragment.java

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

    //Looks like he did this layout via code this is a layoutparams object
    //it defines the metrics and bounds of a specific view
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    //Creating a FrameLayout a FrameLayout is basically a empty container
    FrameLayout fl = new FrameLayout(context);
    fl.setLayoutParams(params);
    //setting the params from above

    // First - image section
    //Building the imageview via code
    LayoutParams imgParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    imgParams.gravity = Gravity.CENTER;//  w  ww .  j  ava  2 s  . com
    //setting all centered
    ImageView iv = new ImageView(context);
    iv.setLayoutParams(imgParams);
    iv.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    iv.setAdjustViewBounds(true);
    iv.setBackgroundResource(getActivity().getIntent().getExtras().getInt("iconID"));
    //seting the iconID as the image of this imageView

    // Second - prices section
    //final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources()
    //        .getDisplayMetrics());
    //

    //LinearLayout is another container it just take the
    //widgets inside it and display them in a linear order
    LinearLayout linLayout = new LinearLayout(context);
    linLayout.setOrientation(LinearLayout.VERTICAL);
    linLayout.setLayoutParams(params);
    linLayout.setGravity(Gravity.CENTER);

    // Get prices
    ConnectionDetector cd = new ConnectionDetector(context); //creating a connection detector to check for internet
    String query = getActivity().getIntent().getStringExtra("searchQuery"); //taking the name or whatever he pass from mainactivity from the searchquery arg
    TextView placeholder = new TextView(context); ///this is a textview for the name of the item
    if (cd.isConnectedToInternet()) {//if its connected to internet then
        if (query.equals("-1")) {//if the skin is regular he display is not for sale
            placeholder.setText("Regular skins are not for sale!");
            linLayout.addView(placeholder);
        } else {//else he calls the scrappperAsyncTask with the query
            new ScraperAsyncTask(linLayout).execute(query);
        }
    } else {//if its not connected he display the message here
        placeholder.setText("Please connect to the Internet to view prices.");
        linLayout.addView(placeholder);
    }

    //here he defines which tab he is displaying, Now I see why he used the same fragment,
    //this is a bad practice, he created both widgets before but just displays one of them
    //for each case if its the first tab he display the image if its the second the prices
    if (position == 0) {
        fl.addView(iv);
    } else {
        fl.addView(linLayout);
    }

    //Then he returns the framelayout (container) to display it in the screen
    return fl;
}

From source file:epmobile.com.android.myapplication.view.OrderListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    activity = getActivity();/*from  www. jav a 2  s  .c  om*/
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.CENTER;
    FrameLayout fl = new FrameLayout(getActivity());
    fl.setLayoutParams(params);
    View rootView = inflater.inflate(R.layout.view_order_list, container, false);
    Bundle args = getArguments();
    deliveryStatus = args.getInt(ORDER_STATUS);
    switch (deliveryStatus) {
    case Order.IN_PROGRESS:
        LOADER_ID = Order.IN_PROGRESS;
        break;
    case Order.CANCELED:
        LOADER_ID = Order.CANCELED;
        break;
    case Order.COMPLETED:
        LOADER_ID = Order.COMPLETED;
        break;
    }

    progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar);
    recyclerView = (RecyclerView) rootView.findViewById(R.id.listOrders);
    recyclerView.addItemDecoration(new DividerItemDecorator(getActivity(), DividerItemDecorator.VERTICAL_LIST));
    recyclerView.setHasFixedSize(true);

    swipeLayoutOrders = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeLayoutOrders);
    swipeLayoutData0 = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeLayoutData0);

    SwipeRefreshLayout.OnRefreshListener listener = new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            refreshList();
        }
    };

    swipeLayoutOrders.setOnRefreshListener(listener);
    swipeLayoutData0.setOnRefreshListener(listener);

    dAdapter = new OrderAdapter(null, R.layout.row_order_list);
    recyclerView.setAdapter(dAdapter);
    mLayoutManager = new LinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.addOnItemTouchListener(
            new RecyclerItemClickListener(getActivity(), new RecyclerItemClickListener.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    Order order = dAdapter.getItemAtPosition(position);
                    Intent intent = new Intent(getActivity(), OrderDetailActivity.class);
                    intent.putExtra(BundleConstants.ORDER, order);
                    startActivity(intent);
                }
            }));
    getLoaderManager().initLoader(LOADER_ID, null, this);
    return rootView;
}

From source file:org.shaastra.helper.SuperAwesomeCardFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*from   ww  w . ja v a2 s  . co m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    FrameLayout fl = new FrameLayout(getActivity());
    fl.setLayoutParams(params);

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

    TextView v = new TextView(getActivity());
    params.setMargins(margin, margin, margin, margin);
    v.setLayoutParams(params);
    v.setLayoutParams(params);
    v.setGravity(Gravity.CENTER);
    //v.setBackgroundResource(R.drawable.background_card);
    v.setText("CARD " + (position + 1));

    if (position == 0) {
        View v1 = inflater.inflate(R.layout.event_info, container, false);
        v1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        TextView t1 = (TextView) v1.findViewById(R.id.infotext);
        t1.setText(eintroduction);
        return v1;
    } else if (position == 1)

    {

        String Venue = new String();
        Venue = evenue;

        final String SAC = elatlong;
        //String start=String.valueOf(l.getLatitude())+String.valueOf(l.getLongitude());
        /*
        View v1=inflater.inflate(R.layout.map, container,false);
        v1.setLayoutParams(params);
        WebView wv=(WebView)v1.findViewById(R.id.wv1);
        wv.setWebChromeClient(new WebChromeClient());
        //wv.loadUrl("https://maps.google.com/maps?saddr=13,80&daddr=13,80.02");
        //wv.loadUrl("http://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal&sensor=false");
        wv.loadUrl("http://maps.google.com/maps?f=d&daddr=51.448,-0.972");
        wv.getSettings().getBuiltInZoomControls();
        */
        View v1 = inflater.inflate(R.layout.map, container, false);
        v1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        TextView location = (TextView) v1.findViewById(R.id.locationText);
        Button mapButton = (Button) v1.findViewById(R.id.mapButton);
        if (evenue.equalsIgnoreCase("NONE")) {
            mapButton.setAlpha(0);
        } else {
            mapButton.setAlpha(1);
        }

        location.setText(Venue);
        mapButton.setOnTouchListener(new View.OnTouchListener() {

            @TargetApi(Build.VERSION_CODES.HONEYCOMB)
            @SuppressLint("NewApi")
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                if (event.getAction() == MotionEvent.ACTION_DOWN) {

                    v.setAlpha((float) 0.4);
                    v.animate().setInterpolator(new DecelerateInterpolator()).scaleX(0.9f).scaleY(0.9f);

                }
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    v.setAlpha((float) 0.75);
                    v.animate().setInterpolator(new OvershootInterpolator()).scaleX(1f).scaleY(1f);

                    Intent intent = new Intent(Intent.ACTION_VIEW,
                            Uri.parse("http://maps.google.com/maps?f=d&daddr=" + SAC));
                    intent.setComponent(new ComponentName("com.google.android.apps.maps",
                            "com.google.android.maps.MapsActivity"));
                    startActivity(intent);
                }

                return false;
            }
        });

        return v1;
    } else if (position == 2) {
        View v1 = inflater.inflate(R.layout.event_info, container, false);
        v1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        TextView t1 = (TextView) v1.findViewById(R.id.infotext);
        t1.setText(eformat);
        return v1;

    } else if (position == 3) {
        View v1 = inflater.inflate(R.layout.prize, container, false);
        v1.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        TextView t1 = (TextView) v1.findViewById(R.id.prizeText);
        t1.setText(eprize);
        return v1;

    } else if (position == 4) {
        v.setBackgroundColor(Color.GREEN);

    } else if (position == 5) {

        v.setBackgroundColor(Color.MAGENTA);

    } else if (position == 6) {
        v.setBackgroundColor(Color.MAGENTA);

    }
    fl.addView(v);
    return fl;

}

From source file:com.jinzht.pro.view.RecyclerViewHeader.java

private void setupAlignment(RecyclerView recycler) {
    if (!mAlreadyAligned) {
        //setting alignment of header
        ViewGroup.LayoutParams currentParams = getLayoutParams();
        FrameLayout.LayoutParams newHeaderParams;
        int width = ViewGroup.LayoutParams.WRAP_CONTENT;
        int height = ViewGroup.LayoutParams.WRAP_CONTENT;
        int gravity = (mReversed ? Gravity.BOTTOM : Gravity.TOP) | Gravity.CENTER_HORIZONTAL;
        if (currentParams != null) {
            newHeaderParams = new FrameLayout.LayoutParams(getLayoutParams()); //to copy all the margins
            newHeaderParams.width = width;
            newHeaderParams.height = height;
            newHeaderParams.gravity = gravity;
        } else {/*from  w w w  .  j  av  a 2  s  .  c o m*/
            newHeaderParams = new FrameLayout.LayoutParams(width, height, gravity);
        }
        RecyclerViewHeader.this.setLayoutParams(newHeaderParams);

        //setting alignment of recycler
        FrameLayout newRootParent = new FrameLayout(recycler.getContext());
        newRootParent.setLayoutParams(recycler.getLayoutParams());
        ViewParent currentParent = recycler.getParent();
        if (currentParent instanceof ViewGroup) {
            int indexWithinParent = ((ViewGroup) currentParent).indexOfChild(recycler);

            ((ViewGroup) currentParent).removeViewAt(indexWithinParent);
            recycler.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT));
            newRootParent.addView(recycler);
            newRootParent.addView(RecyclerViewHeader.this);
            ((ViewGroup) currentParent).addView(newRootParent, indexWithinParent);
        }
    }
}

From source file:net.yanzm.mth.MaterialTabHost.java

public MaterialTabHost(Context context, AttributeSet attrs) {
    super(context, attrs);

    inflater = LayoutInflater.from(context);

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.MaterialTabHost, 0, 0);
    int indicatorColor = a.getColor(R.styleable.MaterialTabHost_colorTabIndicator, Color.YELLOW);
    colorControlActivated = a.getColor(R.styleable.MaterialTabHost_colorBackground, Color.WHITE);

    setBackgroundColor(colorControlActivated);
    a.recycle();//from w  w w. jav  a2 s . co  m

    // ColorDrawable on 2.x does not use getBounds() so use ShapeDrawable
    indicator = new ShapeDrawable();
    indicator.setColorFilter(indicatorColor, PorterDuff.Mode.SRC_ATOP);

    Resources res = context.getResources();
    indicatorHeight = res.getDimensionPixelSize(R.dimen.mth_tab_indicator_height);
    leftOffset = res.getDimensionPixelSize(R.dimen.mth_tab_left_offset);
    int tabHeight = res.getDimensionPixelSize(R.dimen.mth_tab_height);

    tabWidget = new TabWidget(context);
    tabWidget.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, tabHeight));
    tabWidget.setId(android.R.id.tabs);
    tabWidget.setStripEnabled(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        tabWidget.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
    }
    addView(tabWidget);

    FrameLayout fl = new FrameLayout(context);
    fl.setLayoutParams(new LayoutParams(0, 0));
    fl.setId(android.R.id.tabcontent);
    addView(fl);

    setup();

    setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            if (listener != null) {
                listener.onTabSelected(Integer.valueOf(tabId));
            }
        }
    });

    float density = getResources().getDisplayMetrics().density;

    // set elevation for App bar
    // http://www.google.com/design/spec/what-is-material/objects-in-3d-space.html#objects-in-3d-space-elevation
    ViewCompat.setElevation(this, APP_TAB_ELEVATION * density);
}

From source file:com.gandulf.guilib.view.adapter.MultiFragmentPagerAdapter.java

@Override
public Object instantiateItem(View container, int position) {
    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }/*from   ww w. j a v a  2s. co  m*/

    LinearLayout v = new LinearLayout(mContext);
    v.setOrientation(LinearLayout.HORIZONTAL);
    v.setWeightSum(getCount(position));

    int startIndex = getStartIndex(position);

    int containerId = 0;
    final int size = getCount(position);
    for (int i = 0; i < size; i++) {

        containerId = startIndex + i;

        String name = makeFragmentName(container.getId(), containerId);
        Fragment fragment = mFragmentManager.findFragmentByTag(name);

        FrameLayout fragmentView = new FrameLayout(mContext);
        LayoutParams layoutParams = new LayoutParams(0, LayoutParams.MATCH_PARENT, 1);
        fragmentView.setLayoutParams(layoutParams);
        fragmentView.setId(containerId);
        v.addView(fragmentView, i);

        if (fragment != null) {
            Debug.verbose("Attaching item #" + position + ": f=" + fragment + " id:" + containerId);
            mCurTransaction.attach(fragment);
        } else {
            // index is 1 based remove 1 to get a 0-based
            fragment = getItem(position, i);
            if (fragment != null) {
                Debug.verbose("Adding item #" + position + ": f=" + fragment + " id:" + containerId);
                mCurTransaction.add(containerId, fragment, name);
            }
        }
        if (fragment != null && !mCurrentPrimaryItems.contains(fragment)) {
            fragment.setMenuVisibility(false);
            fragment.setUserVisibleHint(false);
        }
    }

    mCurTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);

    ((ViewPager) container).addView(v, 0);

    return v;
}

From source file:com.codeslap.topy.BaseMultiPaneActivity.java

public View getTwoColumns(Fragment firstFragment, float firstWeight, Fragment secondFragment,
        float secondWeight) {
    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);

    int firstId = 1;
    int secondId = 2;

    FrameLayout firstLayout = new FrameLayout(this);
    LinearLayout.LayoutParams firstParams = new LinearLayout.LayoutParams(0,
            LinearLayout.LayoutParams.FILL_PARENT);
    firstParams.weight = firstWeight;//w  w  w .  j  a  va2s . c  o m
    firstLayout.setLayoutParams(firstParams);
    firstLayout.setId(firstId);

    FrameLayout secondLayout = new FrameLayout(this);
    LinearLayout.LayoutParams secondParams = new LinearLayout.LayoutParams(0,
            LinearLayout.LayoutParams.FILL_PARENT);
    secondLayout.setLayoutParams(secondParams);
    secondParams.weight = secondWeight;
    secondLayout.setId(secondId);

    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.add(firstId, firstFragment);
    ft.add(2, secondFragment);
    ft.commit();

    linearLayout.addView(firstLayout);
    linearLayout.addView(secondLayout);

    return linearLayout;
}

From source file:com.esri.android.ecologicalmarineunitexplorer.map.MapActivity.java

public void showSummary(WaterColumn waterColumn) {
    final FragmentManager fm = getSupportFragmentManager();
    SummaryFragment summaryFragment = (SummaryFragment) fm.findFragmentById(R.id.summary_container);
    if (summaryFragment == null) {
        summaryFragment = SummaryFragment.newInstance();
        mSummaryPresenter = new SummaryPresenter(summaryFragment);
    }// www .ja v a  2 s .c  o  m
    mSummaryPresenter.setWaterColumn(waterColumn);

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

    // Adjust the map's layout
    FrameLayout mapLayout = (FrameLayout) findViewById(R.id.map_container);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            0, 7);
    layoutParams.setMargins(0, 0, 36, 0);
    mapLayout.setLayoutParams(layoutParams);
    mapLayout.requestLayout();

    FrameLayout summaryLayout = (FrameLayout) findViewById(R.id.summary_container);
    summaryLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 9));
    summaryLayout.requestLayout();

    // Replace whatever is in the summary_container view with this fragment,
    // and add the transaction to the back stack so the user can navigate back
    transaction.replace(R.id.summary_container, summaryFragment);
    transaction.addToBackStack("summary fragment");

    // Commit the transaction
    transaction.commit();

    WaterColumnFragment waterColumnFragment = (WaterColumnFragment) fm
            .findFragmentById(R.id.water_column_linear_layout_top);
    if (waterColumnFragment == null) {
        waterColumnFragment = WaterColumnFragment.newInstance();
    }
    waterColumnFragment.setWaterColumn(waterColumn);
    FragmentTransaction wcTransaction = getSupportFragmentManager().beginTransaction();
    wcTransaction.replace(R.id.column_container, waterColumnFragment);
    wcTransaction.commit();
}