Android - Adjust button height by checkbox height?

可紊 提交于 2019-12-25 07:57:45

问题


I've got a ListView, one row of which contains Button, CheckBox and multiline TextView. The xml layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:layout_centerVertical="true">

    <Button android:id="@+id/open"
              android:layout_height="wrap_content"
              android:layout_width="wrap_content"
              android:src="@drawable/play"
              android:text="Play"
              android:layout_centerVertical="true"
           />

    <CheckBox android:id="@+id/check"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_centerVertical="true"
             android:layout_toRightOf="@id/open"
           />

    <TextView android:text="@+id/label"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:id="@+id/label"
             android:textSize="16px"
             android:layout_toRightOf="@id/check"
             android:paddingLeft="4px"
           />

</RelativeLayout>

Screenshot of ListView:

How can I adjust the button height with checkbox height?


回答1:


Check out the ALIGN_TOP and ALIGN_BOTTOM properties of relative layout. You can align the top and bottom of your button to the top and bottom of the check box.




回答2:


You can set custom style to the button with lower padding values then the default one.
You can set margin for the button.
You can set a fixed DP value for the buttons height.




回答3:


SOLVED

<Button android:id="@+id/open"
        ...    
        style="?android:attr/buttonStyleSmall"
        ...
        />


来源:https://stackoverflow.com/questions/9262170/android-adjust-button-height-by-checkbox-height

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