下面显示的视图属于登录和聊天片段(可能是一个糟糕的设计理念,但很适合我们的目的)第二个LinearLayout内的ScrollView在发送新消息时滚动:
scroll = (ScrollView) getActivity().findViewById(R.id.scrollView_chat);
//scroll.scrollTo(0, scroll.getBottom()); doesn't work either
scroll.fullScroll(View.FOCUS_DOWN);
两种滚动方式都会产生相同的结果:视图滚动但从不到底部,因此发送的最后一条消息不可见。
这是臭名昭着的视图:
<ViewAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/right_side_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/login_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:id="@+id/username_text"
android:text=""
android:hint="@string/username_hint"
android:inputType="textPersonName"
android:background="#dddddd"
android:imeOptions="flagNavigateNext|flagNoExtractUi"
android:layout_margin="5dp"
android:focusable="true"
android:nextFocusForward="@+id/password_text"
android:nextFocusDown="@+id/password_text"/>
<EditText
android:layout_width="match_parent"
android:layout_height="45dp"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/password_text"
android:text=""
android:hint="@string/password_hint"
android:layout_margin="5dp"
android:background="#dddddd"
android:imeOptions="flagNavigateNext|flagNoExtractUi"
android:nextFocusForward="@+id/login_button"
android:nextFocusDown="@+id/login_button"
android:nextFocusUp="@+id/username_text"/>
<Button
android:id="@+id/login_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/login"
android:layout_margin="5dp"
android:padding="18dp"
android:textColor="#eeeeee"
android:nextFocusUp="@+id/password_text"
android:nextFocusDown="@+id/create_new_account"
android:nextFocusForward="@+id/create_new_account"
android:theme="@style/PrimaryButton"/>
<TextView
android:id="@+id/create_new_account"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/create_new_account"
android:textStyle="bold"
android:textSize="12sp"
android:textAlignment="center"
android:foregroundGravity="bottom"
android:textColor="@color/colorPrimaryDark"
android:clickable="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="20dp"
android:focusable="true"
android:nextFocusUp="@+id/login_button"/>
<ProgressBar
android:id="@+id/progressBarLogin"
style="?android:attr/progressBarStyleInverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
<LinearLayout
android:id="@+id/chat_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="bottom"
android:weightSum="100">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:id="@+id/status_text"
android:gravity="top"
android:visibility="gone"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/scrollView_chat"
android:fillViewport="false"
android:paddingBottom="10dp"
android:layout_weight="80">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:textIsSelectable="true"
android:id="@+id/chatOutputText" />
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="20"
android:layout_gravity="bottom"
android:id="@+id/swag">
<EditText
android:id="@+id/chatInputText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text=""
android:enabled="false"
android:focusable="true"
android:imeOptions="flagNoExtractUi"/>
<ImageButton
android:id="@+id/send_chat_message_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:src="@drawable/ic_send_white_24dp"
android:enabled="false"
android:tint="@android:color/white"
android:layout_gravity="end"
android:theme="@style/PrimaryButtonOval"/>
</LinearLayout>
</LinearLayout>
</ViewAnimator>
知道这里可能出现什么问题?