如何解决移动复选框? [英] How do I fix a moving checkbox?

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

问题描述

我用我的是灰色的,如果不是默认启用code的复选框。这里是$ C $下是相同的:

I am using a checkbox in my code that is grayed out if not enabled by default. Here is the code for the same:

public View getView(final Context context, View view) {
    if (view == null) {
        final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.item_selectable_textview, null);
    }

    final CheckedTextView textView = (CheckedTextView) view.findViewById(R.id.selectable_text);
    textView.setText(mCategoryName);

    if (isDefault()) {
        mIsSelected = true;
    }

    textView.setChecked(mIsSelected);
    if(!isEnabled()){
        textView.setCheckMarkDrawable(R.drawable.checkbox_selected_grayout);
        textView.setBackgroundResource(R.drawable.checkboxline);
        textView.setPadding(20, 20, 20, 20);
    }
    return view;
}

该checkbox_selected_grayout是复选框图像和XML的checkboxline如下:

The checkbox_selected_grayout is the image for checkbox and the xml for checkboxline is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <gradient
                android:startColor="#202020"
                android:endColor="#202020"
                android:angle="360.0" />
        </shape>
    </item>
    <item android:top="40dp">
        <shape android:shape="rectangle">
            <solid android:color="#414141" />
            <size android:height="1dp" />
        </shape>
    </item>
</layer-list>

该复选框看起来很好,当我浏览到视图复选框,但是当我滚动视图的底部,并返回顶端,这似乎是转移到与其他复选框一致的权利,而不是,就如何解决它的任何线索? 注意:当我删除layerlist并切换TI单个形状,它工作正常,没有任何的变化。

The checkbox looks fine when I am navigating to the view with checkbox, However when I scroll to the bottom of the view and return to the top, it appears to be shifting to the right and not aligned with the other check boxes, Any clue on how to fix it? Note: As soon as I remove layerlist and switch ti to a single shape, it works fine without any shifts.

推荐答案

您只需要注释掉行

if (view == null) {

//if (view == null) {

和它应该很好地工作。

这篇关于如何解决移动复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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