2017-01-23 1 views
2

LinearLayout에 설정했습니다. TextView을 스크롤하고 싶습니다. 이런 식으로 xml에 ScrollView을 사용하려고했습니다. 그러나 작동하지 않습니다.android textview scrollview의 scrollview

나는 다른 방법을 시도했지만 여전히 작동하지 않습니다.

android:maxLines = "AN_INTEGER" 
android:scrollbars = "vertical" 

나는 어떻게 TextView 스크롤 할 수 있도록

myTextView.setMovementMethod(new ScrollingMovementMethod()); 

를 사용? 두 번째 경우 ScrollView.

+1

은, 그러나, 안드로이드에서 제공하는 NestedScrollView를 사용해보십시오 유 할 수있는 경우에 중첩 스크롤을 피하기 – Ak9637

+0

예, 그것은 NestedScrollView입니다! 덕분에 도와 줘요,하지만 왜 NestedScrollView 피할해야합니까? –

+0

나는 이것에 대한 기술적 인 대답을 모르지만 안드로이드는 MATERIAL UI – Ak9637

답변

1

스크롤 가능 TextView을 표시하기 위해 NestedScrollView과 함께 ListView을 사용하는 것이 좋습니다.

ListView은 고정 된 크기로되어있어 내부의 전체 높이를 차지하지 않습니다.

레이아웃이 이렇게 보일 수 있습니다.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:padding="8dp" 
    tools:context=".SubpagesLayout.ReportResult"> 

    <!-- first scrollView --> 
    <NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@drawable/edit_corner_blue" 
       android:gravity="center" 
       android:text="@string/personalInformation" 
       android:textColor="@android:color/white" /> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="8dp" 
       android:orientation="horizontal"> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/birthDate" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text=" TestData" /> 
      </LinearLayout> 

      <ListView 
       android:layout_width="match_parent" 
       <!--set a fixed height--> 
       android:layout_height="80dp" 
       .. Other attributes 
      </ListView> 
     </LinearLayout> 
    </NestedScrollView>  
</LinearLayout> 

그리고 ListView의 목록 항목은 TextView 스크롤 할 포함 할 수있다. TextView의 높이를 wrap_content으로 설정합니다.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:padding="8dp" 
    tools:context=".SubpagesLayout.ReportResult"> 

     <TextView 
      android:id="@+id/textOphthalmoscopy" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="standard instrth various settings that allow focusing and adjustment of the light source to accommodate the viewer and to evaluate various features of the fundus." /> 
</LinearLayout> 

이제 ListView가 하나의 항목이되며,이 목록의 기본 동작으로 스크롤됩니다.

전체 레이아웃은 NestedScrollView을 통해 스크롤됩니다.

희망 하시겠습니까?

+0

하, 다시 너야! 정말 도와 줘서 고마워. 이 방법은 새로운 레이아웃을 추가합니다. 더 복잡합니다. 어쨌든 받아들입니다. @Reaz 무릎을 꿇고 –

+0

다시 만나서 반가워요. 도움이 될 경우 upvote하십시오. :) –

1

다른 scrollView 안에 scrollView가있는 것은 좋은 prictice가 아니라 개미가 아래 링크를 확인하여 문제를 해결할 수 있습니다.

Solution 1

중첩 된 스크롤 뷰를 사용할 수 없습니다

Solution 2

+0

나는 솔루션을 설립했다, 감사합니다 @Anti DS –

관련 문제