50807

Android - Adjust button height by checkbox height?

Question:

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:

<img alt="Screenshot of Listview" class="b-lazy" data-src="https://i.stack.imgur.com/2j17E.png" data-original="https://i.stack.imgur.com/2j17E.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

How can I adjust the button height with checkbox height?

Answer1:

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.

Answer2:

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

Answer3:

<strong>SOLVED</strong>

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

Recommend

  • Error producing PDF from TeX source Error: pandoc document conversion failed with error 43 Execution
  • Octave: LaTeX tics
  • PyQt: Create QPixmap with alpha channel and not premultiplied color channels
  • xtable output for a list of tables
  • Android : Create an activity and use it many times with different data [closed]
  • View disappears after setting height of gridLayout to wrap_content
  • TextView shadow not showing up in preview - although working on real device
  • Edittext requestFocus() dynamically not working
  • Android: adding components to RelativeLayout
  • Overlapping ImageView in RelativeView
  • Android custom dialog linearlayout size same as dialogs bg image
  • Background image crashes android
  • How to automatically pop-up keyboard?
  • Float Label hint (TextInputLayout) not works with Android Data Binding
  • Android Custom dialog inflating from layout - alignment issue
  • LyX — Title, Abstract, Keywords Missing When Using Elsevier Class in View
  • EditText ignores the ImeActionLabel
  • Toolbar shifts up, when soft keyboard appears
  • Gray line inside cardview :)?
  • How Lists (specifically, RecyclerView with CardViews) in Android work
  • Bad request using file_get_contents for PUT request in PHP
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Can I make an Android app that runs a web view in Chrome 39?
  • jquery mobile loadPage not working
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • How to stop GridView from loading again when I press back button?
  • LevelDB C iterator
  • Linking SubReports Without LinkChild/LinkMaster
  • Bitwise OR returns boolean when one of operands is nil
  • sending mail using smtp is too slow
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • How can I use `wmic` in a Windows PE script?
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?