单击“复选框”时,Scrollview将消失

时间:2014-10-06 17:13:21

标签: android android-layout checkbox android-emulator scrollview

我的问题是当我点击我的Checkboxt时,ScrollView消失了。该复选框使用OnCheckChangedListener

这是我的布局文件的一部分:

<ScrollView
        android:id="@+id/drawingScrollView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        android:paddingTop="300dp" >

    <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="0dp" >

        <ImageButton
                android:id="@+id/eraseButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/rubber" />

        <CheckBox
                android:id="@+id/unschaerfeFilterCheckBox"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Unschärfefilter AN/AUS"
                android:textSize="12sp" />

        <ImageButton
                android:id="@+id/undoButton"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/undo" />

    </FrameLayout>

</ScrollView>

当我选中并取消选中复选框时,布局应该更改:

unschaerfeFilterCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            // ab 6.2. Zeile
            CheckBox unschaerfeFilterCheckBox = (CheckBox) findViewById(R.id.unschaerfeFilterCheckBox);
            TextView radiusTextView = (TextView) findViewById(R.id.radiusTextView);
            TextView radiusTextMin = (TextView) findViewById(R.id.radiusMinTextView);
            SeekBar unschaerfeSeekBar = (SeekBar) findViewById(R.id.unschaerfeSeekbar);
            RadioButton unschaerfeCheckBox1 = (RadioButton) findViewById(R.id.unschaerfeCheckBox1);
            RadioButton unschaerfeCheckBox2 = (RadioButton) findViewById(R.id.unschaerfeCheckBox2);
            RadioButton unschaerfeCheckBox3 = (RadioButton) findViewById(R.id.unschaerfeCheckBox3);
            RadioButton unschaerfeCheckBox4 = (RadioButton) findViewById(R.id.unschaerfeCheckBox4);

            ScrollView drawingScrollView = (ScrollView)findViewById(R.id.drawingScrollView);
            View view = (View)findViewById(R.id.vorschauView);

            if (isChecked) {

                drawingScrollView.invalidate();
                drawingScrollView.requestLayout();

                view.invalidate();
                view.requestLayout();

                radiusTextView.setVisibility(View.VISIBLE);
                radiusTextMin.setVisibility(View.VISIBLE);
                unschaerfeSeekBar.setVisibility(View.VISIBLE);
                unschaerfeCheckBox1.setVisibility(View.VISIBLE);
                unschaerfeCheckBox2.setVisibility(View.VISIBLE);
                unschaerfeCheckBox3.setVisibility(View.VISIBLE);
                unschaerfeCheckBox4.setVisibility(View.VISIBLE);

                unschaerfeWertIsSet = true;
                unschaerfeLayoutIsSet = true;

                short abstandDurchsichtigkeitsTextOben = (short)(abstandStrichDickeTextOben + strichdickeTextHeight + konstanterAbstand);
                short height = (short)(drawingScrollView.getPaddingTop());

                short abstandUnschaerfeCheckBoxOben = (short)(abstandDurchsichtigkeitsTextOben + durchsichtigkeitsTextHeight + konstanterAbstand /*+ height*/);
                Log.d("abstandUnschaerfeCheckBoxOben", "abstandUnschaerfeCheckBoxOben " + abstandDurchsichtigkeitsTextOben + "|" + abstandUnschaerfeCheckBoxOben + "|" + height); // 64 bei Galaxy s2

                unschaerfeCheckBoxLayout.setMargins(0, abstandUnschaerfeCheckBoxOben, 0, 0);
                unschaerfeFilterCheckBox.setLayoutParams(unschaerfeCheckBoxLayout);

                short abstandRadiusTextLinks = (short)(unschaerfeCheckBoxWidth + konstanterAbstand);
                short abstandRadiusTextOben = (short)(abstandUnschaerfeCheckBoxOben + konstanterAbstand / 2);
                radiusTextViewLayout.setMargins(abstandRadiusTextLinks, abstandRadiusTextOben, 0, 0);
                radiusTextView.setLayoutParams(radiusTextViewLayout);

                short abstandRadiusMinTextLinks = (short)(abstandRadiusTextLinks + radiusTextViewWidth + konstanterAbstand);
                radiusMinTextViewLayout.setMargins(abstandRadiusMinTextLinks, abstandRadiusTextOben, 0, 0);
                radiusTextMin.setLayoutParams(radiusMinTextViewLayout);

...

即使我取消选中复选框,ScrollView仍然会消失。在Emulator(API 16)中,一切都很好用。接下来是,我的手机(API 19)上的位置不正确,但在模拟器中位置是正确的。

这里有一些图片:

(1):按下复选框(手机)之前 before pressing checkbox (mobile phone)

(2):按下复选框(手机)后 - >不再ScrollView,错误的立场 after pressing checkbox (mobile phone)

(3):按下复选框(模拟器)后 - >一切都好 after pressing checkbox (emulator)

请告诉我,当您需要更多java / xml

1 个答案:

答案 0 :(得分:0)

ScrollView view = (ScrollView)findViewById(R.id.scrollView);
view.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
view.setFocusable(true);
view.setFocusableInTouchMode(true);
view.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        v.requestFocusFromTouch();
        return false;
    }
});