【问题标题】:How to create a Check Box which has the "text" in left and box in right?如何创建一个左侧有“文本”,右侧有框的复选框?
【发布时间】:2013-07-31 00:34:24
【问题描述】:

请看下图

我正在使用以下代码动态创建这些复选框

scrollView = (ScrollView)findViewById(R.id.scrollView);
    internalTableLayout = new TableLayout(this);

    for(int i=0;i<20;i++)
    {
        CheckBox c = new CheckBox(this);
        c.setText("Word "+i);

        TableRow r = new TableRow(this);
        r.addView(c);

        internalTableLayout.addView(r);
    }

    scrollView.addView(internalTableLayout);

但是,我需要这些复选框出现在右侧。所以,你知道当它在右手边时,复选框的“文本”首先出现,然后是复选框。

我该怎么做?

【问题讨论】:

标签: android eclipse user-interface checkbox


【解决方案1】:

如果你想使用 CheckBox 小部件并实现相同的效果,那么你可以这样做。

android:button="@null"
android:drawableRight="?android:attr/listChoiceIndicatorMultiple"

【讨论】:

  • 这个!非常感谢。对于那些正在寻找这些默认属性列表的人,它们在您的 SDK 平台安装的 /res/values/attrs.xml 中定义。
【解决方案2】:

使用 CheckedTextView 已经有你想要的 http://developer.android.com/reference/android/widget/CheckedTextView.html

编辑:这是一个重复:How to show android checkbox at right side?How to Set the Checkbox on the right side of the text 因此,如果您需要其他方法来解决它,请检查这些链接,但优雅的方法是 CheckedTextView

【讨论】:

    【解决方案3】:

    您可以按照 Slartibartfast 的建议进行操作,或者创建一个带有“”标签的复选框,并在左侧添加一个单独的 TextView,如果这不符合您的喜好。

    【讨论】:

    • 是的,我用过这个。谢谢你:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多