如何删除复选框右侧不需要的空格? [英] How to remove unwanted spaces at the right of CheckBox?

查看:23
本文介绍了如何删除复选框右侧不需要的空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理自定义列表视图.我想在自定义视图中显示一个 CheckBox.CheckBox 没有文字.我发现 CheckBox 的右侧总是有一些空格.

I am working on a custom list view. I want to show a CheckBox at the custom view. There is no text for the CheckBox. I found it always have some spaces at the right of the CheckBox.

这是我的布局 xml 文件:

Here is my layout xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:background="#fa9654"
android:paddingTop="65dp" android:paddingBottom="65dp">



<TextView android:id="@+id/bus_route_list_item_num"
    android:layout_height="wrap_content" android:layout_width="0dip"
    android:gravity="center" android:layout_gravity="center_vertical|center_horizontal"
    android:layout_weight="0.15"></TextView>

<TextView android:id="@+id/bus_route_list_item_station"
    android:layout_height="wrap_content" android:layout_width="0dip"
    android:gravity="left" android:layout_gravity="center_vertical|center_horizontal"
    android:layout_weight=".5"></TextView>


<TextView android:id="@+id/bus_route_list_item_fee"
    android:layout_height="wrap_content" android:layout_width="0dip"
    android:gravity="center" android:layout_gravity="center_vertical|center_horizontal"
    android:layout_weight=".15"></TextView>


<CheckBox android:id="@+id/bus_route_list_item_reminder" android:layout_height="wrap_content" 
    android:layout_width="0dip" android:layout_weight=".20" android:gravity="center" 
    android:layout_gravity="center" android:paddingRight="0dp" android:paddingLeft="0dp" 
    android:paddingTop="0dp" android:paddingBottom="0dp" android:background="#0066ff" 
    android:text=""
/>

</LinearLayout>

结果如下:
http://pwong.name/checkbox_problem2.jpg

如您所见,复选框右侧有一些空格.我想要的是将复选框放在蓝色区域的中间.

As you can see there are some space at the right of the checkbox. What I want is put the checkbox at the middle of the blue area.

是否可以删除不需要的空间?谢谢

Is it possible to remove the unwanted space? thanks

推荐答案

您可以将 CheckBox 包裹在 LinearLayout 中,然后在该布局上使用 android:gravity="center".

You can wrap CheckBox in LinearLayout and then use android:gravity="center" on that layout.

 <LinearLayout
    android:layout_height="wrap_content"
    android:layout_width="0dip" 
    android:layout_weight=".20"              
    android:background="#ff0000" 
    android:gravity="center">

    <CheckBox android:id="@+id/bus_route_list_item_reminder" 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"                     
    />

</LinearLayout>

作为另一种选择,您可以使用 RelativeLayout.这将大大简化您的布局,您将能够摆脱layout_weight.

As another alternative, you can use RelativeLayout. This would greatly simplify you layout and you will be able to get rid of layout_weight.

这篇关于如何删除复选框右侧不需要的空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆