Example usage for android.view View setLayoutParams

List of usage examples for android.view View setLayoutParams

Introduction

In this page you can find the example usage for android.view View setLayoutParams.

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:com.futurice.hereandnow.view.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;/*w  w  w  . ja  v  a2  s .co m*/
        ImageView tabImageView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            //tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
            tabImageView = (ImageView) tabView.findViewById(R.id.tab_image_view);
        } else {
            tabView = createDefaultTabView(getContext());

        }

        if (tabImageView == null && ImageView.class.isInstance(tabView)) {
            tabImageView = (ImageView) tabView;
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT,
                    1.0f);
            tabView.setLayoutParams(lp);
        }

        //tabTitleView.setText(adapter.getPageTitle(i));
        tabImageView.setBackgroundColor(ViewUtils.getColor(getContext(), i));
        tabImageView.setImageResource(Constants.TAB_ICONS[i]);
        tabView.setOnClickListener(tabClickListener);

        mTabStrip.addView(tabView);
    }
}

From source file:com.google.samples.apps.iosched.ui.widget.CollectionView.java

private View getItemView(RowComputeResult rowInfo, int column, View view, ViewGroup parent) {
    // If there is a custom group container view defined.
    if (hasCustomGroupView()) {
        return createGroupView(rowInfo, view, parent);
    }/*from www.  ja  va2s . c  om*/

    // In the case of regular list view without group containers.
    int indexInGroup = rowInfo.groupOffset + column;
    if (indexInGroup >= rowInfo.group.mItemCount) {
        // out of bounds, so use an empty view
        if (view != null && view instanceof EmptyView) {
            return view;
        }
        view = new EmptyView(getContext());
        view.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        return view;
    }

    if (view == null || view instanceof EmptyView) {
        view = mCallbacks.newCollectionItemView(getContext(), rowInfo.groupId, parent);
    }

    mCallbacks.bindCollectionItemView(getContext(), view, rowInfo.groupId, indexInGroup,
            rowInfo.group.getDataIndex(indexInGroup), rowInfo.group.getItemTag(rowInfo.groupOffset + column));
    return view;
}

From source file:com.sgottard.sofa.support.BrowseSupportFragment.java

void setSearchOrbViewOnScreen(boolean onScreen) {
    View searchOrbView = getTitleView().getSearchAffordanceView();
    MarginLayoutParams lp = (MarginLayoutParams) searchOrbView.getLayoutParams();
    lp.setMarginStart(onScreen ? 0 : -mContainerListMarginStart);
    searchOrbView.setLayoutParams(lp);
}

From source file:app.learning.fantaster.nhatkyhoctiengnhat.util.slidingtab.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;/*from www.j  a  v a2 s  . c o  m*/

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        CharSequence title = adapter.getPageTitle(i);
        tabTitleView.setText(title);
        tabTitleView.setGravity(Gravity.CENTER_HORIZONTAL);
        tabTitleView.setTextColor(Color.WHITE);
        tabView.setOnClickListener(tabClickListener);

        if (mDistributeEvenly) {
            tabView.setLayoutParams(layoutParams);
        }

        mTabStrip.addView(tabView);
    }
}

From source file:com.raspi.chatapp.ui.chatting.SendImageFragment.java

private void keyboardOpened() {
    if (!keyboardShown) {
        try {/*ww  w .j  a v  a 2  s . co  m*/
            View buttons = getActivity().findViewById(R.id.send_image_buttons);
            View viewPager = getActivity().findViewById(R.id.send_image_view_pager);
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            params.addRule(RelativeLayout.ALIGN_PARENT_START);
            viewPager.setLayoutParams(params);
            RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            imageParams.addRule(RelativeLayout.ABOVE, R.id.send_image_description_layout);
            images.get(current).getImageLayout().setLayoutParams(imageParams);
            if (images.size() > 1)
                getActivity().findViewById(R.id.send_image_overview).setVisibility(View.GONE);
            buttons.setVisibility(View.GONE);
            hideSystemUI();
        } catch (Exception e) {
            e.printStackTrace();
        }
        keyboardShown = true;
    }
}

From source file:com.google.samples.apps.iosched.ui.SessionLivestreamActivity.java

/**
 * Adjusts phone layouts for full screen video.
 *//*from   w  ww . j av a2 s  .  com*/
private void layoutPhoneFullscreen(boolean fullscreen) {
    View youTubePlayerView = mYouTubeFragment.getView();
    if (youTubePlayerView != null) {
        ViewGroup.LayoutParams playerParams = mYouTubeFragment.getView().getLayoutParams();
        playerParams.height = fullscreen ? LayoutParams.MATCH_PARENT : LayoutParams.WRAP_CONTENT;
        youTubePlayerView.setLayoutParams(playerParams);
    }

    final LayoutParams containerParams = (LayoutParams) mPlayerContainer.getLayoutParams();
    containerParams.height = fullscreen ? LayoutParams.MATCH_PARENT : LayoutParams.WRAP_CONTENT;
    mPlayerContainer.setLayoutParams(containerParams);

    if (fullscreen) {
        mTabsContentLayout.setVisibility(View.GONE);
        if (mYouTubePlayer != null) {
            mYouTubePlayer.setFullscreen(true);
        }
    } else {
        mTabsContentLayout.setVisibility(View.VISIBLE);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
}

From source file:com.chauthai.overscroll.BouncyAdapter.java

/**
 * Create a transparent gap view to insert into the adapter as header or footer.
 *///ww  w . j a v  a  2  s .  co m
private View createGapView() {
    final View view = new View(mContext);
    final int width = directionVertical() ? ViewGroup.LayoutParams.MATCH_PARENT : (int) dpToPx(GAP_SIZE);
    final int height = directionVertical() ? (int) dpToPx(GAP_SIZE) : ViewGroup.LayoutParams.MATCH_PARENT;

    final ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(width, height);

    if (directionVertical()) {
        params.width = 1;
    } else {
        params.height = 1;
    }

    view.setLayoutParams(params);

    return view;
}

From source file:jp.co.ipublishing.esnavi.activities.MapActivity.java

/**
 * ????????/*w w w .  j  a  v  a2s .c  o m*/
 *
 * @param alert 
 */
private void updateLayout(@Nullable final Alert alert) {
    // ??

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            final View legendView = mLegendFragment.getView();
            final View mapView = mMapFragment.getView();

            if (legendView != null && mapView != null) {
                final LinearLayout.LayoutParams legendParams = (LinearLayout.LayoutParams) legendView
                        .getLayoutParams();
                final LinearLayout.LayoutParams mapParams = (LinearLayout.LayoutParams) mapView
                        .getLayoutParams();

                // FIXME: activity_map.xml?layout_weight???????????
                if (alert != null && alert.isEvacuationSituation()) {
                    // ???????
                    legendParams.weight = 3.0f;
                    mapParams.weight = 19.0f;
                } else {
                    // ????????
                    legendParams.weight = 0.0f;
                    mapParams.weight = 22.0f;
                }

                legendView.setLayoutParams(legendParams);
                mapView.setLayoutParams(mapParams);
            } else {
                // ?????????????????
                if (legendView == null) {
                    Log.w(TAG, "legendView is null...");
                }
                if (mapView == null) {
                    Log.w(TAG, "mapView is null...");
                }
            }
        }
    });
}

From source file:eu.operando.operandoapp.OperandoProxyStatus.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    MainUtil.initializeMainContext(getApplicationContext());
    Settings settings = mainContext.getSettings();
    settings.initializeDefaultValues();//from w  w  w .jav a  2  s .co m
    setCurrentThemeStyle(settings.getThemeStyle());
    setTheme(getCurrentThemeStyle().themeAppCompatStyle());
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);
    settings.registerOnSharedPreferenceChangeListener(this);

    webView = (WebView) findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);

    //region Floating Action Button

    fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (MainUtil.isServiceRunning(mainContext.getContext(), ProxyService.class)
                    && !MainUtil.isProxyPaused(mainContext)) {
                //Update Preferences to BypassProxy
                MainUtil.setProxyPaused(mainContext, true);
                fab.setImageResource(android.R.drawable.ic_media_play);
                //Toast.makeText(mainContext.getContext(), "-- bypass (disable) proxy --", Toast.LENGTH_SHORT).show();
            } else if (MainUtil.isServiceRunning(mainContext.getContext(), ProxyService.class)
                    && MainUtil.isProxyPaused(mainContext)) {

                MainUtil.setProxyPaused(mainContext, false);
                fab.setImageResource(android.R.drawable.ic_media_pause);
                //Toast.makeText(mainContext.getContext(), "-- re-enable proxy --", Toast.LENGTH_SHORT).show();
            } else if (!mainContext.getAuthority()
                    .aliasFile(BouncyCastleSslEngineSource.KEY_STORE_FILE_EXTENSION).exists()) {
                try {
                    installCert();
                } catch (RootCertificateException | GeneralSecurityException | OperatorCreationException
                        | IOException ex) {
                    Logger.error(this, ex.getMessage(), ex.getCause());
                }
            }
        }
    });

    //endregion

    //region TabHost

    final TabHost tabHost = (TabHost) findViewById(R.id.tabHost2);
    tabHost.setup();

    TabHost.TabSpec tabSpec = tabHost.newTabSpec("wifi_ap");
    tabSpec.setContent(R.id.WifiAndAccessPointsScrollView);
    tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_home));
    tabHost.addTab(tabSpec);

    tabSpec = tabHost.newTabSpec("response_domain_filters");
    tabSpec.setContent(R.id.ResponseAndDomainFiltersScrollView);
    tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_filter));
    tabHost.addTab(tabSpec);

    tabSpec = tabHost.newTabSpec("pending_notifications");
    tabSpec.setContent(R.id.PendingNotificationsScrollView);
    tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_pending_notification));
    tabHost.addTab(tabSpec);

    tabSpec = tabHost.newTabSpec("logs");
    tabSpec.setContent(R.id.LogsScrollView);
    tabSpec.setIndicator("", getResources().getDrawable(R.drawable.ic_report));
    tabHost.addTab(tabSpec);

    tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            switch (tabId) {
            case "pending_notifications":
                //region Load Tab3
                ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.PendingNotificationsScrollView))
                        .getChildAt(0)).getChildAt(1)).removeAllViews();
                LoadPendingNotificationsTab();
                //endregion
                break;
            case "logs":
                //region Load Tab 4
                //because it is a heavy task it is being loaded asynchronously
                ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.LogsScrollView)).getChildAt(0))
                        .getChildAt(1)).removeAllViews();
                new AsyncTask() {
                    private ProgressDialog mProgress;
                    private List<String[]> apps;

                    @Override
                    protected void onPreExecute() {
                        super.onPreExecute();
                        mProgress = new ProgressDialog(MainActivity.this);
                        mProgress.setCancelable(false);
                        mProgress.setCanceledOnTouchOutside(false);
                        mProgress.setTitle("Fetching Application Data Logs");
                        mProgress.show();
                    }

                    @Override
                    protected Object doInBackground(Object[] params) {
                        apps = new ArrayList();
                        for (String[] app : getInstalledApps(false)) {
                            apps.add(new String[] { app[0], GetDataForApp(Integer.parseInt(app[1])) });
                        }
                        return null;
                    }

                    @Override
                    protected void onPostExecute(Object o) {
                        super.onPostExecute(o);
                        mProgress.dismiss();
                        for (String[] app : apps) {
                            if (app[0].contains(".")) {
                                continue;
                            }
                            TextView tv = new TextView(MainActivity.this);
                            tv.setTextSize(18);
                            tv.setText(app[0] + " || " + app[1]);
                            ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.LogsScrollView))
                                    .getChildAt(0)).getChildAt(1)).addView(tv);

                            View separator = new View(MainActivity.this);
                            separator.setBackgroundColor(Color.BLACK);
                            separator.setLayoutParams(
                                    new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 5));
                            ((TableLayout) ((LinearLayout) ((ScrollView) findViewById(R.id.LogsScrollView))
                                    .getChildAt(0)).getChildAt(1)).addView(separator);
                        }
                    }
                }.execute();
                //endregion
                break;
            }
        }
    });

    //endregion

    //region Buttons

    WiFiAPButton = (Button) findViewById(R.id.WiFiAPButton);
    WiFiAPButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent i = new Intent(mainContext.getContext(), AccessPointsActivity.class);
            startActivity(i);
        }
    });

    responseFiltersButton = (Button) findViewById(R.id.responseFiltersButton);
    responseFiltersButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(mainContext.getContext(), ResponseFiltersActivity.class);
            startActivity(i);
        }
    });

    domainFiltersButton = (Button) findViewById(R.id.domainFiltersButton);
    domainFiltersButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(mainContext.getContext(), DomainFiltersActivity.class);
            startActivity(i);
        }
    });

    domainManagerButton = (Button) findViewById(R.id.domainManagerButton);
    domainManagerButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(mainContext.getContext(), DomainManagerActivity.class);
            startActivity(i);
        }
    });

    permissionsPerDomainButton = (Button) findViewById(R.id.permissionsPerDomainButton);
    permissionsPerDomainButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(mainContext.getContext(), PermissionsPerDomainActivity.class);
            startActivity(i);
        }
    });

    trustedAccessPointsButton = (Button) findViewById(R.id.trustedAccessPointsButton);
    trustedAccessPointsButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(mainContext.getContext(), TrustedAccessPointsActivity.class);
            startActivity(i);
        }
    });

    updateButton = (Button) findViewById(R.id.updateButton);
    updateButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // mark first time has not runned and update like it's initial .
            final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
            SharedPreferences.Editor editor = prefs.edit();
            editor.putBoolean("firstTime", true);
            editor.commit();
            DownloadInitialSettings();
        }
    });

    statisticsButton = (Button) findViewById(R.id.statisticsButton);
    statisticsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(mainContext.getContext(), StatisticsActivity.class);
            startActivity(i);
        }
    });

    //endregion

    //region Action Bar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        setTitle(R.string.app_name);
    }

    //endregion

    //region Send Cached Settings
    //send cached settings if exist...
    BufferedReader br = null;
    try {
        File file = new File(MainContext.INSTANCE.getContext().getFilesDir(), "resend.inf");
        StringBuilder content = new StringBuilder();
        br = new BufferedReader(new FileReader(file));
        String line;
        while ((line = br.readLine()) != null) {
            content.append(line);
        }
        if (content.toString().equals("1")) {
            File f = new File(file.getCanonicalPath());
            f.delete();
            new DatabaseHelper(MainActivity.this)
                    .sendSettingsToServer(new RequestFilterUtil(MainActivity.this).getIMEI());
        }
    } catch (Exception ex) {
        ex.getMessage();
    } finally {
        try {
            br.close();
        } catch (Exception ex) {
            ex.getMessage();
        }
    }
    //endregion

    initializeProxyService();
}

From source file:com.raspi.chatapp.ui.chatting.SendImageFragment.java

private void keyboardClosed() {
    if (keyboardShown) {
        try {/*from w  ww. ja  v a 2  s . com*/
            showSystemUI();
            View buttons = getActivity().findViewById(R.id.send_image_buttons);
            View viewPager = getActivity().findViewById(R.id.send_image_view_pager);
            RelativeLayout.LayoutParams viewPagerParams = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            viewPagerParams.addRule(RelativeLayout.ABOVE, R.id.send_image_overview);
            viewPagerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            viewPagerParams.addRule(RelativeLayout.ALIGN_PARENT_START);
            viewPager.setLayoutParams(viewPagerParams);
            RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
            imageParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
            images.get(current).getImageLayout().setLayoutParams(imageParams);
            if (images.size() > 1)
                getActivity().findViewById(R.id.send_image_overview).setVisibility(View.VISIBLE);
            buttons.setVisibility(View.VISIBLE);
        } catch (Exception e) {
            e.printStackTrace();
        }
        keyboardShown = false;
    }
}