2011-07-02 47 views
9

Tôi mới vào Android tôi muốn ScrollText trong EditText và cũng cho thấy Scrollbar ở corner.I Scroll theText Bởi Sử dụngAndroid làm thế nào để thiết lập ScrollBar trong Edittext?

questionEntry.setScroller(new Scroller(myContext)); 
questionEntry.setMaxLines(1); 
questionEntry.setVerticalScrollBarEnabled(true); 
questionEntry.setMovementMethod(new ScrollingMovementMethod()); 

scr0lling của văn bản làm việc Nhưng ScrollBar doesnot có được Visible bất cứ ai có thể cho tôi một Sugesstion?

Trả lời

17

Điều này có thể giúp bạn.

<EditText android:id="@+id/edt_task_disc" android:layout_width="wrap_content" 
         android:layout_height="wrap_content" android:gravity="top" 
         android:background="@drawable/text_aerea" 
         android:hint="Task Discription" 
         android:textSize="15sp" android:paddingLeft="5dp" 
         android:maxHeight="35dp" 
         android:scrollbars="vertical" 
         /> 

Vui lòng thêm android:scrollbars="vertical" vào mã xml của văn bản chỉnh sửa và nó sẽ hoạt động tốt.

3

Chỉ mẫu

Trong file Java của bạn

EditText dwEdit = (EditText) findViewById(R.id.DwEdit); 

dwEdit.setOnTouchListener(new OnTouchListener() { 

       public boolean onTouch(View view, MotionEvent event) { 
        // TODO Auto-generated method stub 
        if (view.getId() ==R.id.DwEdit) { 
         view.getParent().requestDisallowInterceptTouchEvent(true); 
         switch (event.getAction()&MotionEvent.ACTION_MASK){ 
         case MotionEvent.ACTION_UP: 
          view.getParent().requestDisallowInterceptTouchEvent(false); 
          break; 
         } 
        } 
        return false; 
       } 
      }); 

Và trong tập tin Xml của bạn ...

<EditText 
     android:id="@+id/DwEdit" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="9" 
     android:ems="10" 
     android:gravity="top" 
     android:imeOptions="flagNoExtractUi" 

     android:minLines="10" 
     android:scrollHorizontally="false" 
     android:scrollbarAlwaysDrawVerticalTrack="true" 
     android:scrollbarStyle="insideInset" 
     android:scrollbars="vertical" 
     android:overScrollMode="always" 
     android:inputType="textCapSentences"> 
     </EditText> 
Các vấn đề liên quan