【问题标题】:Android Layout with 2 TextViews on left and CheckBox on right has text over checkbox左侧有 2 个 TextView 和右侧 CheckBox 的 Android 布局在复选框上有文本
【发布时间】:2011-09-28 12:00:14
【问题描述】:

我试图有一个复杂的 ListView,它在左侧有一个标题和描述,在右侧有一个复选框。我正在这样做,但左侧的文本超出了右侧的复选框。

我怎样才能防止这种情况发生?

我的布局代码目前看起来像:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:paddingLeft="15dip">
<CheckBox
    android:id="@+id/list_checkbox" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:checked="false"
    />   
<TextView
    android:text="Some Title"
    android:id="@+id/list_complex_title"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_toLeftOf="@+id/list_checkbox"
    android:textAppearance="?android:attr/textAppearanceLarge"
    />    
<TextView
    android:text="Some long description Some long description Some long description Some long description Some long description."
    android:id="@+id/list_complex_caption"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#98AFC7"
    android:layout_below="@+id/list_complex_title"
    android:textAppearance="?android:attr/textAppearanceSmall"
    />
</RelativeLayout>

不幸的是,我是该网站的新手,需要更多积分才能发布图片:(

如果可能,我也希望复选框垂直居中。

任何布局专家?

【问题讨论】:

    标签: android layout


    【解决方案1】:

    写一个声明

    android:layout_toLeftOf="@+id/list_checkbox"
    

    在您的描述文本视图中,这样它就不会转到复选框

    【讨论】:

    • 非常感谢!有没有办法让我垂直居中该复选框?
    • 我能够垂直居中:android:layout_centerInParent="true"
    • 在你的复选框中写一行 android:layout_centerVertical="true"
    【解决方案2】:

    无事可做。 . 根据您的布局代码,只需将左边距留给越过复选框的 TextView。 它会解决你的问题。 我已经做到了。

    【讨论】:

    • 如果您将左边距设置为 TextView 它如何解决这个问题?它将保留左侧空间,但不会解决此问题。TextView 包装在复选框右侧
    • @Dhrmendra :如果你给 TextView 的左边距与复选框的宽度相同,它不会在复选框上继续。而这个问题的问题是文本不应该越过复选框。
    • 问题是左侧的文本越过了右侧的复选框。他在他的问题中提到过。再检查一次。
    • 我认为 user914453 已经通过我的回答解决了问题,所以现在结束了。感谢您的回复。
    猜你喜欢
    • 1970-01-01
    • 2016-12-29
    • 2013-07-31
    • 1970-01-01
    • 2010-12-17
    • 1970-01-01
    • 2012-06-19
    • 2022-01-19
    • 2015-07-25
    相关资源
    最近更新 更多