滚动型并不直接调整孩子的变化后, [英] ScrollView does not resize directly after child changes

查看:135
本文介绍了滚动型并不直接调整孩子的变化后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰到的一个非常恼人的问题,关于滚动型调整大小,和我跑出来的可能的解决方案。

I've run into a very annoying problem regarding ScrollView resizing, and I'm running out of possible solutions.

我有一个包含几个不同的片段,其中之一有一个滚动型中FragmentPager。 用滚动型的片段是由一个微调和含有的LinearLayout与几排其它视图(如SeekBars,按钮Edittexts)在它的滚动型的。 根据该选项的微调选择,滚动视图显示了不同的看法。要做到这一点,一些观点都有其知名度转身走了,而另一些则转向可见。 这个伟大的工程,除了一个事实,即滚动型似乎并不在选择使用微调不同的选项正确调整自己。

I have a FragmentPager containing several different Fragments, one of which has a ScrollView. The Fragment with the ScrollView is made up of a Spinner and the ScrollView containing a LinearLayout with several rows of other Views (such as SeekBars, Buttons, Edittexts) in it. Depending on which option is select in the Spinner, the ScrollView shows different views. To do so, some Views have their visibility turned to Gone, while others are turned to Visible. This works great, except for the fact that the ScrollView does not seem to resize itself properly upon choosing a different option using the Spinner.

在滚动型是全景,因此滚动,如果用户选择一个选项,显示出较低的Viewsthan要求仍然填充视口的滚动型滚动。 当用户然后再选择旧选项,滚动型是现在无法滚动,因为它承担了所需的previous选项的大小。 当用户然后再次选择相同的选项,滚动型突然是滚动的,因为它现在调整到所需的实际尺寸。

When the ScrollView is full of Views, and therefore scrollable, if the user selects an option which shows less Viewsthan required to fill the ViewPort the ScrollView still scrolls. When the user then chooses the old option again, the ScrollView is now unable to scroll since it took on the size required for the previous option. When the user then chooses the SAME option again, the ScrollView suddenly is scrollable, since it is now resized to the actual size required.

这是怎么回事呢?而更好的是,我怎么能解决这个恼人的问题?

What is going on here? And better yet, how can I fix this annoying problem?

我的布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/control_scroll"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="#99000000"
    android:fillViewport="true" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#DD000000"
            android:gravity="bottom"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/lamp_choose_tv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:paddingLeft="5dp"
                android:text="@string/choose_lamp_text"
                android:textColor="#FFFFFF"
                android:textSize="14sp" />
        </LinearLayout>

        <Spinner
            android:id="@+id/lamp_select_spinner"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:textColor="#FFFFFF" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#DD000000"
            android:gravity="bottom"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/lamp_settings_tv"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2dp"
                android:background="#44000000"
                android:paddingLeft="5dp"
                android:text="@string/lamp_settings_text"
                android:textColor="#FFFFFF"
                android:textSize="14sp" />
        </LinearLayout>
        <!-- Lamp name -->

        <LinearLayout
            android:id="@+id/naam_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="bottom"
            android:paddingBottom="3dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="3dp" >

            <TextView
                android:id="@+id/bridge_naam"
                style="@style/ConfigText"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/config_lightname"
                android:textColor="#FFFFFF"
                android:textSize="16sp" />

            <EditText
                android:id="@+id/lamp_naam_input"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:background="@drawable/tasstextfield"
                android:inputType="textNoSuggestions"
                android:textColor="#FFFFFF" >
            </EditText>
        </LinearLayout>

        <View
            android:id="@+id/separator"
            android:layout_width="fill_parent"
            android:layout_height="0.5dp"
            android:background="@android:color/black"
            android:visibility="visible" />
<!-- Rest of the views -->

我已经尝试过

东西:

Things I already tried:

  • ForceLayout / requestLayout父滚动型
  • 无效的滚动型
  • ForceLayout / requestLayout在含有的LinearLayout
  • 的无效化的LinearLayout
  • 的无效化滚动型的所有子
  • ForceLayout / requestLayout上的滚动型
  • 的所有子
  • ForceLayout/requestLayout on the parent ScrollView
  • Invalidate the ScrollView
  • ForceLayout/requestLayout on the containing LinearLayout
  • Invalidating the LinearLayout
  • Invalidating all children of the ScrollView
  • ForceLayout/requestLayout on all children of the ScrollView

推荐答案

这可能不是最愉快的解决方案,但它可能工作。 使用一个处理器发布延迟的消息,刷新视图第二次,因为如果用户将其上的刷新按钮,点击后选择相同的选项两次。

This might not be the most enjoyable solution, but it might work. Use a handler to post a delayed message to refresh the view a second time, as if the user would choose the same option twice after having click on the refresh button.

// The code when the user wants to update the views 
myButton.setOnClickListener(new OnClickListener{
  @Override
  public void onClick(View view) {
    updateView();
    Message m = Message.obtain();
    m.what = UPDATE_TAG;
    mHandler.sendMessageDelayed(msg, 200);
  }
})

...

final int UPDATE_TAG = 1;

public void updateView() {
  // Code where View.GONE and View.VISIBLE + invalidate is used.
}

Handler mHandler = new Handler {
  @Override
  public void handleMessage(Message input_msg) {
    if(msg.what == UPDATE_TAG) {
      updateView();
    }
  }
}

这篇关于滚动型并不直接调整孩子的变化后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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