0

来自片段布局Demo:
有一个simple_list_item_checkable_1.xml

<com.example.android.supportv4.view.CheckableFrameLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    <TextView
            android:id="@android:id/text1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:minHeight="?android:attr/listPreferredItemHeight"
            android:gravity="center_vertical"
    />
</com.example.android.supportv4.view.CheckableFrameLayout>

有一堂课CheckableFrameLayout.java

public class CheckableFrameLayout extends FrameLayout implements Checkable {
    private boolean mChecked;

    public CheckableFrameLayout(Context context) {
        super(context);
    }

    public CheckableFrameLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void setChecked(boolean checked) {
        mChecked = checked;
        setBackgroundDrawable(checked ? new ColorDrawable(0xff0000a0) : null);
    }

    public boolean isChecked() {
        return mChecked;
    }

    public void toggle() {
        setChecked(!mChecked);
    }

}

我真的不知道为什么演示会以这种方式编写,我可以将其切换为 XML 代码吗?
我试过谷歌,但我仍然找不到任何答案。

4

1 回答 1

0

CheckableFrameLayout 是自定义显示元素,而不是内置的 Android UI 小部件。它的行为在源代码中定义,它的 UI 在 XML 中定义。

于 2013-01-15T10:20:44.817 回答