2011-12-26 51 views
7

在我的應用程序中,我使用EditText編寫郵件說明,並按照以下內容進行製作。 我的edittext有多行。 當我輸入更多行並嘗試在edittext中從下往上移動時,edittext的滾動不起作用。如何在scrollview中滾動edittext?

任何人都可以幫助我嗎? 謝謝..

<ScrollView 
    android:id="@+id/scrollView" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:scrollbarStyle="insideOverlay"> 

      <EditText 
       android:id="@+id/edBody" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:lines="5" 
       android:scrollbars="vertical" 
       android:text="" 
       android:inputType="textMultiLine"/>  


    </ScrollView> 
+0

嗨,你可以請幫助我,如果你找到任何解決這個問題。 – Raj 2012-08-06 10:59:00

回答

0

試試這個希望對大家的工作

EditText et=(EditText)findViewById(R.id.edbody); 
et.setMovementMethod(new ScrollingMovementMethod()); 

在活動

+0

它沒有爲我工作。 – Raj 2012-08-06 10:58:34

+0

仍然沒有得到答案。 – 2012-10-25 17:00:18

1

試試這個

main.xml中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
    > 
    <EditText 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:text="Loooooooooonng loooooooooong teeeeeeeeeeext" 
     android:id="@+id/et" 
     android:maxLines = "100" 
     android:scrollbars = "vertical" 
     /> 
</LinearLayout> 

MyActivity.java

public class MyActivity extends Activity { 
    private EditText et; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     et= (EditText) findViewById(R.id.et); 
     et.setMovementMethod(new ScrollingMovementMethod()); 
    } 
} 

注意:不能在ScrollView中放置可滾動控件(例如ListView)。我認爲它不適用於可滾動的EditText進入ScrollView。

+1

爲我工作.. – Reshma 2015-04-22 06:22:58

0

首先爲您的滾動視圖創建您的ID,然後在您的方法中寫入此代碼後。

et.setOnTouchListener(new View.OnTouchListener() { 
      @Override 
      public boolean onTouch(View view, MotionEvent motionEvent) { 
       mScrollMain.requestDisallowInterceptTouchEvent(true); 
       return false; 
      } 
     }); 

cahnge聽到mScrollMain與滾動視圖對象。 他們工作肯定