List of usage examples for android.view View setLayoutParams
public void setLayoutParams(ViewGroup.LayoutParams params)
From source file:com.ashlikun.badgeview.BadgeView.java
public void setTargetView(View target) { if (getParent() != null) { ((ViewGroup) getParent()).removeView(this); }/*from ww w.ja v a2 s .c o m*/ if (target == null) { return; } if (target.getParent() instanceof FrameLayout) { ((FrameLayout) target.getParent()).addView(this); } else if (target.getParent() instanceof ViewGroup) { // use a new Framelayout container for adding badge ViewGroup parentContainer = (ViewGroup) target.getParent(); int groupIndex = parentContainer.indexOfChild(target); parentContainer.removeView(target); FrameLayout badgeContainer = new FrameLayout(getContext()); ViewGroup.LayoutParams parentLayoutParams = target.getLayoutParams(); badgeContainer.setLayoutParams(parentLayoutParams); target.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); parentContainer.addView(badgeContainer, groupIndex, parentLayoutParams); badgeContainer.addView(target); badgeContainer.addView(this); } else if (target.getParent() == null) { Log.e(getClass().getSimpleName(), "ParentView is needed"); } }
From source file:com.sdei.slidingtabs.SlidingTabLayout.java
private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null; TextView tabTitleView = null;/* w w w .j av a2 s . c om*/ if (mTabViewLayoutId != 0) { 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; } tabTitleView.setText(adapter.getPageTitle(i)); tabView.setOnClickListener(tabClickListener); if (mDistributeEvenly) { LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f); tabView.setLayoutParams(lp); } mTabStrip.addView(tabView); } }
From source file:com.nextgis.mobile.fragment.AttributesFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (mLayer == null) { getActivity().getSupportFragmentManager().popBackStack(); Toast.makeText(getContext(), R.string.error_layer_not_inited, Toast.LENGTH_SHORT).show(); return null; }//from ww w . jav a 2 s . c om getActivity().setTitle(mLayer.getName()); setHasOptionsMenu(!isTablet()); int resId = isTablet() ? R.layout.fragment_attributes_tab : R.layout.fragment_attributes; View view = inflater.inflate(resId, container, false); if (isTablet()) { FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(view.getLayoutParams()); Display display = getActivity().getWindowManager().getDefaultDisplay(); DisplayMetrics metrics = new DisplayMetrics(); display.getMetrics(metrics); lp.width = metrics.widthPixels / 2; int[] attrs = { R.attr.actionBarSize }; TypedArray ta = getActivity().obtainStyledAttributes(attrs); lp.bottomMargin = ta.getDimensionPixelSize(0, 0); ta.recycle(); view.setLayoutParams(lp); } mAttributes = (LinearLayout) view.findViewById(R.id.ll_attributes); return view; }
From source file:com.phoenixmarketcity.android.phoenix.activities.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 ww w. 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; } if (mDistributeEvenly) { LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1); tabView.setLayoutParams(lp); } tabTitleView.setText(adapter.getPageTitle(i)); tabView.setOnClickListener(tabClickListener); mTabStrip.addView(tabView); if (i == mViewPager.getCurrentItem()) { tabView.setSelected(true); } } }
From source file:com.anan.anancooking.client.ui.customLayout.SlidingTabLayout.java
private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null; TextView tabTitleView = null;/*from w w w.j a va 2 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; } tabTitleView.setText(adapter.getPageTitle(i)); tabTitleView.setTextColor(getResources().getColor(R.color.text_secondary)); tabView.setOnClickListener(tabClickListener); tabView.setLayoutParams(new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1)); mTabStrip.addView(tabView); } }
From source file:com.asgj.android.appusage.ui.widgets.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 w w w . j ava2s . co 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()); LinearLayout.LayoutParams tabViewParams = (LinearLayout.LayoutParams) tabView.getLayoutParams(); if (tabViewParams == null) tabViewParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); tabViewParams.weight = 1; tabView.setLayoutParams(tabViewParams); } if (tabTitleView == null && TextView.class.isInstance(tabView)) { tabTitleView = (TextView) tabView; } tabTitleView.setTextSize(15); tabTitleView.setText(adapter.getPageTitle(i)); tabView.setOnClickListener(tabClickListener); mTabStrip.addView(tabView); } }
From source file:com.android.deskclock.timer.TimerFullScreenFragment.java
@Override public void onResume() { Intent newIntent = null;//from www . jav a 2 s . c o m if (getActivity() instanceof DeskClock) { DeskClock activity = (DeskClock) getActivity(); activity.registerPageChangedListener(this); newIntent = activity.getIntent(); } super.onResume(); mPrefs.registerOnSharedPreferenceChangeListener(this); mAdapter = createAdapter(getActivity()); mAdapter.onRestoreInstanceState(null); LayoutParams params; float dividerHeight = getResources().getDimension(R.dimen.timer_divider_height); if (getActivity() instanceof DeskClock) { // If this is a DeskClock fragment (i.e. not a FullScreenTimerAlert), add a footer to // the bottom of the list so that it can scroll underneath the bottom button bar. // StaggeredGridView doesn't support a footer view, but GridAdapter does, so this // can't happen until the Adapter itself is instantiated. View footerView = getActivity().getLayoutInflater().inflate(R.layout.blank_footer_view, mTimersList, false); params = footerView.getLayoutParams(); params.height -= dividerHeight; footerView.setLayoutParams(params); mAdapter.setFooterView(footerView); } if (mPrefs.getBoolean(Timers.REFRESH_UI_WITH_LATEST_DATA, false)) { // Clear the flag indicating the adapter is out of sync with the database. mPrefs.edit().putBoolean(Timers.REFRESH_UI_WITH_LATEST_DATA, false).apply(); } mTimersList.setAdapter(mAdapter); setTimerListPosition(mAdapter.getCount()); mLastVisibleView = null; // Force a non animation setting of the view setPage(); // View was hidden in onPause, make sure it is visible now. View v = getView(); if (v != null) { getView().setVisibility(View.VISIBLE); } if (newIntent != null) { processIntent(newIntent); } mFab.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { final Animator revealAnimator = getRevealAnimator(mFab, Color.WHITE); revealAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { updateAllTimesUpTimers(); } }); revealAnimator.start(); } }); }
From source file:com.google.android.gcm.demo.ui.MainActivity.java
/** * Toggle the Logs View visibility with a nice animation. *//* ww w. j a v a 2 s. com*/ public void toggleLogsView(boolean showView) { final View logsView = findViewById(R.id.logs_layout); final View bodyView = findViewById(R.id.container); final FrameLayout.LayoutParams logsLayoutParams = (FrameLayout.LayoutParams) logsView.getLayoutParams(); final int startLogsY, endLogsY, startBodyY, endBodyY; if (showView) { // The logsView height set in XML is a placeholder, we need to compute at runtime // how much is 0.4 of the screen height. int height = (int) (0.4 * mDrawerLayout.getHeight()); // The LogsView is hidden being placed off-screen with a negative bottomMargin. // We need to update its height and bottomMargin to the correct runtime values. logsLayoutParams.bottomMargin = -logsLayoutParams.height; logsView.setLayoutParams(logsLayoutParams); logsLayoutParams.height = height; // Prepare the value for the Show animation. startLogsY = logsLayoutParams.bottomMargin; endLogsY = 0; startBodyY = 0; endBodyY = logsLayoutParams.height; } else { // Prepare the value for the Hide animation. startLogsY = 0; endLogsY = -logsLayoutParams.height; startBodyY = logsLayoutParams.height; endBodyY = 0; } final int deltaLogsY = endLogsY - startLogsY; final int deltaBodyY = endBodyY - startBodyY; Animation a = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { logsLayoutParams.bottomMargin = (int) (startLogsY + deltaLogsY * interpolatedTime); logsView.setLayoutParams(logsLayoutParams); bodyView.setPadding(0, 0, 0, (int) (startBodyY + deltaBodyY * interpolatedTime)); } }; a.setDuration(500); logsView.startAnimation(a); }
From source file:com.sj.android.appusage.ui.widgets.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 . jav a 2 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()); LinearLayout.LayoutParams tabViewParams = (LinearLayout.LayoutParams) tabView.getLayoutParams(); if (tabViewParams == null) tabViewParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); tabViewParams.weight = 1; tabView.setLayoutParams(tabViewParams); } if (tabTitleView == null && TextView.class.isInstance(tabView)) { tabTitleView = (TextView) tabView; } if (i == mViewPager.getCurrentItem()) { tabTitleView.setTextColor(Color.WHITE); tabTitleView.setAlpha(1.0f); } else { tabTitleView.setTextColor(Color.WHITE); tabTitleView.setAlpha(0.5f); } tabTitleView.setTextSize(15); tabTitleView.setText(adapter.getPageTitle(i)); tabView.setOnClickListener(tabClickListener); mTabStrip.addView(tabView); } }
From source file:com.andrada.sitracker.ui.fragment.DirectoryChooserFragment.java
@Override public View onCreateView(@NotNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { assert getActivity() != null; final View view = inflater.inflate(R.layout.directory_chooser, container, false); mBtnConfirm = (Button) view.findViewById(R.id.btnConfirm); Button mBtnCancel = (Button) view.findViewById(R.id.btnCancel); mBtnNavUp = (ImageButton) view.findViewById(R.id.btnNavUp); mBtnCreateFolder = (ImageButton) view.findViewById(R.id.btnCreateFolder); mTxtvSelectedFolderLabel = (TextView) view.findViewById(R.id.txtvSelectedFolderLabel); mTxtvSelectedFolder = (TextView) view.findViewById(R.id.txtvSelectedFolder); ListView mListDirectories = (ListView) view.findViewById(R.id.directoryList); if (!mIsDirectoryChooser) { mBtnConfirm.setVisibility(View.GONE); View horDivider = view.findViewById(R.id.horizontalDivider); if (horDivider != null) { horDivider.setVisibility(View.INVISIBLE); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) horDivider.getLayoutParams(); params.addRule(RelativeLayout.CENTER_HORIZONTAL, 0); params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); horDivider.setLayoutParams(params); }/* ww w. j a v a2 s . c o m*/ } else { mBtnConfirm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isValidFile(mSelectedDir) && mIsDirectoryChooser) { returnSelectedFolder(); } } }); } mBtnCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mListener.onCancelChooser(); } }); mListDirectories.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View view, int position, long id) { debug("Selected index: %d", position); if (mFilesInDir != null && position >= 0 && position < mFilesInDir.length) { changeDirectory(mFilesInDir[position]); } } }); mBtnNavUp.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { File parent; if (mSelectedDir != null && (parent = mSelectedDir.getParentFile()) != null) { changeDirectory(parent); } } }); mBtnCreateFolder.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { openNewFolderDialog(); } }); if (!getShowsDialog()) { mBtnCreateFolder.setVisibility(View.GONE); } adjustResourceLightness(); mFilenames = new ArrayList<FileDescriptor>(); mListDirectoriesAdapter = new FolderArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, mFilenames); mListDirectories.setAdapter(mListDirectoriesAdapter); final File initialDir; if (mInitialDirectory != null && isValidFile(new File(mInitialDirectory))) { initialDir = new File(mInitialDirectory); } else { initialDir = Environment.getExternalStorageDirectory(); } changeDirectory(initialDir); return view; }