Java Code Examples for androidx.drawerlayout.widget.DrawerLayout#LayoutParams
The following examples show how to use
androidx.drawerlayout.widget.DrawerLayout#LayoutParams .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewUtils.java From DevUtils with Apache License 2.0 | 6 votes |
/** * 获取 View Layout Gravity * @param view {@link View} * @return Layout Gravity */ public static int getLayoutGravity(final View view) { if (view != null) { try { if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) { return ((LinearLayout.LayoutParams) view.getLayoutParams()).gravity; } else if (view.getLayoutParams() instanceof FrameLayout.LayoutParams) { return ((FrameLayout.LayoutParams) view.getLayoutParams()).gravity; } else if (view.getLayoutParams() instanceof ViewPager.LayoutParams) { return ((ViewPager.LayoutParams) view.getLayoutParams()).gravity; } else if (view.getLayoutParams() instanceof CoordinatorLayout.LayoutParams) { return ((CoordinatorLayout.LayoutParams) view.getLayoutParams()).gravity; } else if (view.getLayoutParams() instanceof DrawerLayout.LayoutParams) { return ((DrawerLayout.LayoutParams) view.getLayoutParams()).gravity; } else { // 抛出不支持的类型 throw new Exception("layoutParams:" + view.getLayoutParams().toString()); } } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "getLayoutGravity"); } } return 0; }
Example 2
Source File: ViewUtils.java From DevUtils with Apache License 2.0 | 6 votes |
/** * 设置 View Layout Gravity * @param view {@link View} * @param gravity Gravity * @return {@code true} success, {@code false} fail */ public static boolean setLayoutGravity(final View view, final int gravity) { if (view != null) { try { if (view.getLayoutParams() instanceof LinearLayout.LayoutParams) { ((LinearLayout.LayoutParams) view.getLayoutParams()).gravity = gravity; } else if (view.getLayoutParams() instanceof FrameLayout.LayoutParams) { ((FrameLayout.LayoutParams) view.getLayoutParams()).gravity = gravity; } else if (view.getLayoutParams() instanceof ViewPager.LayoutParams) { ((ViewPager.LayoutParams) view.getLayoutParams()).gravity = gravity; } else if (view.getLayoutParams() instanceof CoordinatorLayout.LayoutParams) { ((CoordinatorLayout.LayoutParams) view.getLayoutParams()).gravity = gravity; } else if (view.getLayoutParams() instanceof DrawerLayout.LayoutParams) { ((DrawerLayout.LayoutParams) view.getLayoutParams()).gravity = gravity; } else { // 抛出不支持的类型 throw new Exception("layoutParams:" + view.getLayoutParams().toString()); } return true; } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "setLayoutGravity"); } } return false; }
Example 3
Source File: ArcNavigationView.java From ArcNavigationView with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") @SuppressLint("RtlHardcoded") private void adjustChildViews(ViewGroup container) { final int containerChildCount = container.getChildCount(); PathMeasure pathMeasure = new PathMeasure(arcPath, false); DrawerLayout.LayoutParams layoutParams = (DrawerLayout.LayoutParams) getLayoutParams(); for (int i = 0; i < containerChildCount; i++) { View child = container.getChildAt(i); if (child instanceof ViewGroup) { adjustChildViews((ViewGroup) child); } else { float[] pathCenterPointForItem = {0f, 0f}; Rect location = locateView(child); int halfHeight = location.height() / 2; pathMeasure.getPosTan(location.top + halfHeight, pathCenterPointForItem, null); if (layoutParams.gravity == Gravity.END || layoutParams.gravity == Gravity.RIGHT) { int centerPathPoint = getMeasuredWidth() - Math.round(pathCenterPointForItem[0]); if (child.getMeasuredWidth() > centerPathPoint) { child.measure(MeasureSpec.makeMeasureSpec(centerPathPoint - THRESHOLD, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec( child.getMeasuredHeight(), MeasureSpec.EXACTLY)); child.layout(centerPathPoint + THRESHOLD, child.getTop(), child.getRight(), child.getBottom()); } } else if (layoutParams.gravity == Gravity.START || layoutParams.gravity == Gravity.LEFT) { if (child.getMeasuredWidth() > pathCenterPointForItem[0]) { child.measure(MeasureSpec.makeMeasureSpec((Math.round(pathCenterPointForItem[0]) - THRESHOLD), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec( child.getMeasuredHeight(), MeasureSpec.EXACTLY)); child.layout(child.getLeft(), child.getTop(), (Math.round(pathCenterPointForItem[0]) - THRESHOLD), child.getBottom()); } } //set text ellipsize to end to prevent it from overlapping edge if (child instanceof TextView) { ((TextView) child).setEllipsize(TextUtils.TruncateAt.END); } } } }
Example 4
Source File: MainActivity.java From habpanelviewer with GNU General Public License v3.0 | 4 votes |
@Override public void onStart() { super.onStart(); Intent permissionIntent = PermissionUtil.createRequestPermissionsIntent(this); if (permissionIntent != null) { startActivityForResult(permissionIntent, Constants.REQUEST_VALIDATE); return; } final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainActivity.this); NavigationView navigationView = findViewById(R.id.nav_view); DrawerLayout.LayoutParams params = (DrawerLayout.LayoutParams) navigationView.getLayoutParams(); final String menuPos = prefs.getString(Constants.PREF_MENU_POSITION, ""); if (getString(R.string.left).equalsIgnoreCase(menuPos)) { params.gravity = Gravity.START; } else { params.gravity = Gravity.END; } if (mRestartingExceptionHandler != null) { mRestartingExceptionHandler.updateFromPreferences(prefs); } if (mCommandQueue != null) { mCommandQueue.updateFromPreferences(prefs); } if (mCapturer == null && prefs.getBoolean(Constants.PREF_CAPTURE_SCREEN_ENABLED, false)) { MediaProjectionManager projectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE); startActivityForResult(projectionManager.createScreenCaptureIntent(), Constants.REQUEST_MEDIA_PROJECTION); } else if (mCapturer != null && !prefs.getBoolean(Constants.PREF_CAPTURE_SCREEN_ENABLED, false)) { mCapturer.terminate(); mCapturer = null; } for (IDeviceMonitor m : mMonitors) { m.updateFromPreferences(prefs); } mConnectedIndicator.updateFromPreferences(prefs); mWebView.updateFromPreferences(prefs); mServerConnection.updateFromPreferences(prefs, this); updateMotionPreferences(); if (prefs.getBoolean(Constants.PREF_SHOW_CONTEXT_MENU, true)) { registerForContextMenu(mWebView); } else { unregisterForContextMenu(mWebView); } }
Example 5
Source File: ArcNavigationView.java From ArcNavigationView with Apache License 2.0 | 4 votes |
@SuppressLint("RtlHardcoded") private Path createClipPath() { final Path path = new Path(); arcPath = new Path(); float arcWidth = settings.getArcWidth(); DrawerLayout.LayoutParams layoutParams = (DrawerLayout.LayoutParams) getLayoutParams(); if (settings.isCropInside()) { if (layoutParams.gravity == Gravity.START || layoutParams.gravity == Gravity.LEFT) { arcPath.moveTo(width, 0); arcPath.quadTo(width - arcWidth, height / 2.0f, width, height); arcPath.close(); path.moveTo(0, 0); path.lineTo(width, 0); path.quadTo(width - arcWidth, height / 2.0f, width, height); path.lineTo(0, height); path.close(); } else if (layoutParams.gravity == Gravity.END || layoutParams.gravity == Gravity.RIGHT) { arcPath.moveTo(0, 0); arcPath.quadTo(arcWidth, height / 2.0f, 0, height); arcPath.close(); path.moveTo(width, 0); path.lineTo(0, 0); path.quadTo(arcWidth, height / 2.0f, 0, height); path.lineTo(width, height); path.close(); } } else { if (layoutParams.gravity == Gravity.START || layoutParams.gravity == Gravity.LEFT) { arcPath.moveTo(width - arcWidth / 2, 0); arcPath.quadTo(width + arcWidth / 2, height / 2.0f, width - arcWidth / 2, height); arcPath.close(); path.moveTo(0, 0); path.lineTo(width - arcWidth / 2, 0); path.quadTo(width + arcWidth / 2, height / 2.0f, width - arcWidth / 2, height); path.lineTo(0, height); path.close(); } else if (layoutParams.gravity == Gravity.END || layoutParams.gravity == Gravity.RIGHT) { arcPath.moveTo(arcWidth / 2, 0); arcPath.quadTo(-arcWidth / 2, height / 2.0f, arcWidth / 2, height); arcPath.close(); path.moveTo(width, 0); path.lineTo(arcWidth / 2, 0); path.quadTo(-arcWidth / 2, height / 2.0f, arcWidth / 2, height); path.lineTo(width, height); path.close(); } } return path; }
Example 6
Source File: SideMenuRoot.java From react-native-navigation with MIT License | 4 votes |
private DrawerLayout.LayoutParams createLayoutParams(SideMenuOptions options, int gravity) { return new DrawerLayout.LayoutParams(getWidth(options), getHeight(options), gravity); }