简体   繁体   English

设置工具栏的重力(RelativeLayout)

[英]Set Gravity for Toolbar (RelativeLayout)

i need to set Gravity programmatically to Bottom. 我需要以编程方式将“重力”设置为“底部”。 It's loks like the default value is Top.The attributes in the Comment specifically for the Toolbar on this Fragment. 看起来像默认值是Top。Comment中的属性专门用于此Fragment的工具栏。 My Idea is to add the chances on onCreateView and remove onDetach. 我的想法是在onCreateView上添加机会并删除onDetach。

private Toolbar toolbar;
private ViewGroup.LayoutParams params;

 RelativeLayout.LayoutParams newParams = new
 RelativeLayout.LayoutParams(toolbar.getLayoutParams());
 params = new RelativeLayout.LayoutParams(toolbar.getLayoutParams());
 newParams.height = dpToPx(128);
 //need to set gravity
 toolbar.setPadding(0, 0, 0, dpToPx(28));

 toolbar.setLayoutParams(newParams);

 /*android:layout_height="128dp"
   android:gravity="bottom""
   android:paddingBottom="28dp"*/

Thanks 谢谢

To move one of the toolbar controls to the bottom of the toolbar, don't set the layout parameters on the toolbar itself. 要将工具栏控件之一移至工具栏底部,请不要在工具栏本身上设置布局参数。 You need to set the gravity of the view you are trying to move: 您需要设置要移动的视图的重力:

control.setGravity(Gravity.BOTTOM);
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/primary"
    android:minHeight="?attr/actionBarSize"
    android:gravity="bottom"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

First with android:gravity="bottom" 首先使用android:gravity="bottom"

图片

图片

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM