我想将复选框统一到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... -->


预习:

最佳答案

您可以根据CompoundButton.OnCheckedChangeListenerCheckbox调用以下方法。与输入参数中一样,提供对要平滑过渡折叠/展开的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);
}

08-19 08:26