1

我想将复选框统一到 LinearLayout 上的一个可滚动窗口。(对不起我的英语)这里有什么办法吗?我是java新手。我对每个复选框都有一个条件。

<CheckBox
        android:id="@+id/checkBox7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/emod1"
        android:textSize="@dimen/texty_v_menu" />

<!-- ... and 5 another checkBoxes... -->

预习:

在此处输入图像描述

4

1 回答 1

0

您可以根据CompoundButton.OnCheckedChangeListener您的Checkbox. 与输入参数一样,提供对View您希望通过平滑过渡折叠/展开的引用。

/**
 * Allows a view to be collapsed and Gone with a smooth animation
 * @param v view to be collapsed and gone
 */
public static void collapseView(final View v) {
    final int initialHeight = v.getMeasuredHeight();

    final Animation a = new Animation(){
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            if(interpolatedTime == 1){
                v.setVisibility(View.GONE);
            }else{
                v.getLayoutParams().height = initialHeight - (int)(initialHeight * interpolatedTime);
                v.requestLayout();
            }
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    a.setDuration(500);
    v.startAnimation(a);
}


/**
 * Allows a collapsed and Gone view to be expanded and Visible
 * @param v view to be expanded and Visible
 */
public static void expandView(final View v) {
    v.measure(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    final int targtetHeight = v.getMeasuredHeight();

    v.getLayoutParams().height = 0;
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation(){
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1
                    ? LayoutParams.WRAP_CONTENT
                    : (int)(targtetHeight * interpolatedTime);
            v.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    a.setDuration(500);
    v.startAnimation(a);
}
于 2013-10-22T07:16:10.733 回答