【问题标题】:Android textview height and checkbox in listview列表视图中的Android textview高度和复选框
【发布时间】:2012-03-15 14:46:09
【问题描述】:

我有一个带有文本视图和复选框的自定义列表视图。这是xml文件:

 <TextView android:id="@+id/rowTextView"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"  
     android:layout_weight="1"
     android:background="#222222"/>

<CheckBox
    android:id="@+id/CheckBox01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:focusable="false"
    >
</CheckBox>

结果:

我在 textview 中添加了一个 bg 颜色来查看它的高度。问题是当我单击文本视图(黑色空间)时,复选框被(未)选中。当我点击 textview 时,复选框保持状态。我试图扩展 textview (40dip) 的高度,但结果如下:

如何将 textview 的高度设置为复选框的高度?

【问题讨论】:

    标签: android listview checkbox textview


    【解决方案1】:

    尝试将 textView 和 CheckBox 保持在不同的线性布局中。并检查一下,这可能会解决您的问题。

    【讨论】:

      【解决方案2】:

      您可以将自定义样式设置为具有比默认值更低的填充值的按钮。 您可以设置按钮的边距。 您可以为按钮高度设置一个固定的 DP 值。

      style="?android:attr/buttonStyleSmall" ... />

      【讨论】:

        【解决方案3】:

        这就是解决方案。不完美,但它正在工作。

        <?xml version="1.0" encoding="utf-8"?>
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content">
        
          <TextView android:id="@+id/rowTextView" 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:paddingTop="15dip"
            android:paddingBottom="15dip"
            android:background="#222222">
          </TextView>
        
          <CheckBox android:id="@+id/CheckBox01" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:layout_alignParentRight="true" android:layout_marginRight="6sp"
            android:focusable="false">
          </CheckBox>
        
        </RelativeLayout>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-02-24
          • 1970-01-01
          • 2015-03-19
          • 2016-04-26
          • 2016-03-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多