2016-11-30 18 views
0

我在ScrollView中有幾個EditText s。一個EditText下面有一個TextView。當軟鍵盤專注於EditText我想滾動到上面提到的TextView,所以我確定它也可見(它包含一些關於EditText的信息)。無法滾動到scrollView中的特定視圖

所以我添加了一個焦點偵聽到EditText裏邊有我有這樣的代碼:

 svContainer.postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       svContainer.smoothScrollTo(0 , tvInfo.getBottom()); 


      } 
     }, 300); 

但沒有任何反應。鍵盤下方隱藏着TextView。 logcat的讓我對tvInfo.getBottom() == 717

編輯:雖然如果我改變smoothScrollTo()svContainer.fullScroll(View.FOCUS_DOWN);那麼它所有的方式滾動至底部!

編輯2:增加了XML代碼

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" 
xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingPrefix" 
android:id="@+id/sv_container" 
android:fillViewport="false" android:background="@color/getstarted_blue_bg" 
android:layout_width="match_parent" android:layout_height="wrap_content"> 

<LinearLayout 
    android:id="@+id/ll_about_you_container" 
    android:orientation="vertical" android:layout_marginTop="@dimen/spacing_xlarge" 
    android:layout_width="match_parent" android:layout_height="wrap_content"> 

    <TextView 
     android:text="@string/get_started_about_you" android:textColor="@color/white" android:textStyle="bold" 
     android:layout_marginLeft="@dimen/spacing_large" android:layout_marginRight="@dimen/spacing_large" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" /> 

    <EditText 
     android:id="@+id/et_industry" 
     android:maxLines="1" android:imeOptions="actionNext" android:inputType="textCapSentences" 
     android:nextFocusForward="@+id/et_profession" 
     android:layout_marginLeft="@dimen/spacing_large" android:layout_marginRight="@dimen/spacing_large" 
     android:layout_marginTop="@dimen/spacing_large" android:textColor="@color/white" android:textSize="@dimen/app_text_size_large" 
     android:layout_width="match_parent" android:layout_height="wrap_content" /> 

    <EditText 
     android:id="@+id/et_profession" 
     android:nextFocusForward="@+id/et_company" 
     android:maxLines="1" android:imeOptions="actionNext" android:inputType="textCapSentences" 
     android:layout_marginLeft="@dimen/spacing_large" android:layout_marginRight="@dimen/spacing_large" 
     android:layout_marginTop="@dimen/spacing_large" android:textColor="@color/white" android:textSize="@dimen/app_text_size_large" 
     android:layout_width="match_parent" android:layout_height="wrap_content" /> 

    <EditText 
     android:id="@+id/et_company" 
     android:hint="@string/get_started_company" android:textColorHint="@color/white" 
     android:maxLines="1" android:imeOptions="actionNext" android:inputType="textCapSentences" 
     android:layout_marginLeft="@dimen/spacing_large" android:layout_marginRight="@dimen/spacing_large" 
     android:layout_marginTop="@dimen/spacing_large" android:textColor="@color/white" android:textSize="@dimen/app_text_size_large" 
     android:layout_width="match_parent" android:layout_height="wrap_content" /> 

    <TextView 
     android:id="@+id/tv_anchor" 
     android:layout_gravity="center" 
     android:text="AnchorView" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" /> 

</LinearLayout> 

</ScrollView> 

回答

0

用途:

svContainer.post(new Runnable() { 
      @Override 
      public void run() { 
       svContainer.scrollTo(0, tvInfo.getBottom()); 
      } 
     }); 
    } 

與用途: 在活動標籤清單中:

android:windowSoftInputMode="stateHidden" 
+0

我以前也試過,但仍然沒有滾動 – Mes

+0

好吧讓我再試'stateHidden' – Mes

+0

不能'stateHidden '沒有幫助 – Mes