2014-10-06 2 views
0

하나의 하위 레이아웃 (선형 레이아웃)을 포함하는 스크롤보기가 있고 그 자식은 상대 레이아웃과 선형 레이아웃을 포함합니다. 상대 레이아웃과 선형 레이아웃은 화면 절반을 공유합니다. 선형 레이아웃에는 동적으로 단추가 추가되었습니다.ScrollView가 오버플로 된 레이아웃을 스크롤하지 않습니다.

이제 상대적인 레이아웃과 선형 레이아웃을 스크롤하는 동안 스크롤 뷰는 스크롤하지 않기 때문에 문제가 발생합니다.

<ScrollView> 
<LinearLayout> 

    <RelativeLayout>  
    </RelativeLayout> 

    <LinearLayout> 
          ->Dynamically adding buttons here 
    </LinearLayout> 

</LinearLayout> 
</ScrollView> 

내가 그 버튼이있는 ScrollView로 이동합니다

참고로 내 XML 코드는 다음과 같습니다 -

<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:background="@color/whitecolor" 
android:orientation="vertical" 
> 

<ScrollView 
    android:id="@+id/scrollview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" 
    > 

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

<RelativeLayout 
    android: 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:orientation="vertical" 
    > 
<View 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/bluecolor" 
    /> 
<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/stauslinearlayout" 
    android:layout_marginBottom="8dp" 
    android:padding="5dp" 
    android:gravity="center" 
    android:textColor="@color/whitecolor" 
    android:text="@string/app_name" 
    /> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_alignParentBottom="true" 
    android:background="@color/bluecolor" 
    > 
<EditText 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:background="@drawable/edit_text_custom" 
    android:singleLine="true" 
    android:hint="@string/status" 
    android:textColor="#000" 
    android:textColorHint="#5222" 
    android:padding="7dp" 
    android:maxLength="50" 
    android:cursorVisible="true" 
    android:layout_marginBottom="10dp" 
    android:layout_marginLeft="10dp" 
    android:drawableLeft="@android:drawable/ic_input_add" 
    android:ems="10" 
    /> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="right|center_horizontal" 
    android:gravity="center" 
    android:layout_weight="0" 
    android:layout_marginBottom="10dp" 
    android:layout_marginRight="10dp" 
    android:padding="5dp" 
    android:text="@string/statusnumber" 
    android:background="@drawable/edit_text_custom" 
    /> 
</LinearLayout> 
</RelativeLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:orientation="vertical" 
    > 
<TextView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/whitecolor" 
    android:text="abcdfrg" 
    /> 
<Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/app_name" 
    /> 
<Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/app_name" 
    /> 
    <Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/app_name" 
    /> 
    <Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/app_name" 
    /> 
     <Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/app_name" 
    /> 
     <Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/app_name" 
    />    
</LinearLayout> 
</LinearLayout> 
</ScrollView> 

답변

0

AFAIK, 당신이 동일하여 화면을 분할하려면 두 가지 크기, 아래 예제와 같이 다른 scrollView 뷰를 가져와야합니다 ...

<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" > 

    <ScrollView 
     android:id="@+id/scrollview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:fillViewport="true" > 

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

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:orientation="vertical" > 

       <View 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@android:color/darker_gray" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_above="@+id/stauslinearlayout" 
        android:layout_marginBottom="8dp" 
        android:gravity="center" 
        android:padding="5dp" 
        android:text="@string/app_name" 
        android:textColor="@android:color/white" /> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" 
        android:background="@android:color/darker_gray" 
        android:orientation="horizontal" > 

        <EditText 
         android:layout_width="0dp" 
         android:layout_height="wrap_content" 
         android:layout_marginBottom="10dp" 
         android:layout_marginLeft="10dp" 
         android:layout_weight="1" 
         android:cursorVisible="true" 
         android:drawableLeft="@android:drawable/ic_input_add" 
         android:ems="10" 
         android:hint="status" 
         android:maxLength="50" 
         android:padding="7dp" 
         android:singleLine="true" 
         android:textColor="#000" 
         android:textColorHint="#5222" /> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="match_parent" 
         android:layout_gravity="right|center_horizontal" 
         android:layout_marginBottom="10dp" 
         android:layout_marginRight="10dp" 
         android:layout_weight="0" 
         android:gravity="center" 
         android:padding="5dp" 
         android:text="statusnumber" /> 
       </LinearLayout> 
      </RelativeLayout> 

      <ScrollView 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" > 

       <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="@android:color/white" 
         android:text="abcdfrg" /> 

        <Button 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="@string/app_name" /> 

        <Button 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="@string/app_name" /> 

        <Button 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="@string/app_name" /> 

        <Button 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="@string/app_name" /> 

        <Button 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="@string/app_name" /> 

        <Button 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="@string/app_name" /> 
       </LinearLayout> 
      </ScrollView> 
     </LinearLayout> 
    </ScrollView> 

</LinearLayout> 

다른 scrollView를 사용하지 않으려면 하단 선형 레이아웃에 wrap_contant를 지정해야합니다.

<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" > 

    <ScrollView 
     android:id="@+id/scrollview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:fillViewport="true" > 

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

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:orientation="vertical" > 

       <View 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@android:color/darker_gray" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_above="@+id/stauslinearlayout" 
        android:layout_marginBottom="8dp" 
        android:gravity="center" 
        android:padding="5dp" 
        android:text="@string/app_name" 
        android:textColor="@android:color/white" /> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" 
        android:background="@android:color/darker_gray" 
        android:orientation="horizontal" > 

        <EditText 
         android:layout_width="0dp" 
         android:layout_height="wrap_content" 
         android:layout_marginBottom="10dp" 
         android:layout_marginLeft="10dp" 
         android:layout_weight="1" 
         android:cursorVisible="true" 
         android:drawableLeft="@android:drawable/ic_input_add" 
         android:ems="10" 
         android:hint="status" 
         android:maxLength="50" 
         android:padding="7dp" 
         android:singleLine="true" 
         android:textColor="#000" 
         android:textColorHint="#5222" /> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="match_parent" 
         android:layout_gravity="right|center_horizontal" 
         android:layout_marginBottom="10dp" 
         android:layout_marginRight="10dp" 
         android:layout_weight="0" 
         android:gravity="center" 
         android:padding="5dp" 
         android:text="statusnumber" /> 
       </LinearLayout> 
      </RelativeLayout> 

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

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@android:color/white" 
        android:text="abcdfrg" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/app_name" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/app_name" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/app_name" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/app_name" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/app_name" /> 

       <Button 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/app_name" /> 
      </LinearLayout> 
     </LinearLayout> 
    </ScrollView> 

</LinearLayout> 

선택 사항은 귀하의 요구 사항에 달려 있습니다.

아직 문제가 있다면 plz ask ... :-)

+0

두 자식 레이아웃 모두 단일 스크롤보기로 스크롤하기를 원하기 때문에 첫 번째 방법을 사용할 수 없습니다. 두 번째 방법은 내 문제와 같은 행동을하는 동안. 그러나 동적으로 첫 번째 자식 높이를 화면 높이/2로 설정 한 다음 동적으로 스크롤 뷰에 단추를 추가하여이 작업을 수행했습니다. 고마워요! – Aviverma

+0

@Aviverma, 오신 것을 환영합니다. – Rumit

관련 문제