Android Button in Gridlayout don't have same margin top

放肆的年华 提交于 2019-12-11 10:19:50

问题


I got a GridLayout, and there will be two or more buttons in the layout, and all the buttons must with same width. My problem is that when the buttons having different line number of text, the marginTop of button will different too. How can I fix this? Thanks.

<GridLayout
    android:id="@+id/grid_buddies"
    android:columnCount="4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <Button
        android:layout_width="60dp"
        android:layout_height="match_parent"
        android:text="TEST"/>
    <Button
        android:layout_width="60dp"
        android:layout_height="wrap_content"
        android:text="TESTDDFF"/>
</GridLayout>

Here is the picture:


回答1:


Use android:layout_gravity="fill_vertical" attribute in your Button with text TEST

<GridLayout
    android:id="@+id/grid_buddies"
    android:columnCount="4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <Button
       android:layout_width="60dp"
       android:layout_height="match_parent"
       android:text="TEST"
       android:layout_gravity="fill_vertical"/>
    <Button
       android:layout_width="60dp"
       android:layout_height="wrap_content"
       android:text="TESTDDFF"/>
</GridLayout>


来源:https://stackoverflow.com/questions/16644203/android-button-in-gridlayout-dont-have-same-margin-top

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!