1

내 응용 프로그램의 홈페이지에 모든 섹션의 항목 목록이 포함 된 다른 섹션이 있어야합니다. 이를 위해 ScrollView을 사용했습니다. scrollview 안에 검색 영역과 ExpandableHeightGridView (이 항목은 GridView이 항목 수에 따라 ScrollView 내부의 공간을 확장하는 데 도움이되는 사용자 지정 클래스)을 넣습니다.ExpandableHeightGridView가있는 ScrollView가 스크롤되지 않습니다.

그러나 scrollView가 작동하지 않고 검색 상자가 화면 상단에 나타나고 GridView은 ScrollView 내부에없는 것처럼 스크롤합니다.

다음은 내 코드입니다 :

activity_main.xml

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/njoftime_background"> 


    <ScrollView 
     android:id="@+id/sv" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/white"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/white" 
      android:layout_marginTop="?android:attr/actionBarSize" 
      android:orientation="vertical"> 


      <RelativeLayout 
       android:id="@+id/sr" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="10dp" 
       android:background="@drawable/event_background_block" 
       android:padding="5dp"> 

       <RelativeLayout 
        android:id="@+id/search_area" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:focusableInTouchMode="true" 
        android:background="@drawable/njoftime_item_background"> 

        <ImageButton 
         android:id="@+id/btn_search" 
         android:layout_width="65dp" 
         android:layout_height="35dp" 
         android:layout_alignParentRight="true" 
         android:layout_marginLeft="1dp" 
         android:background="@color/njoftime_main_color" 
         android:onClick="searchPressed" 
         android:scaleType="fitCenter" 
         android:src="@drawable/ic_search_white" /> 

        <EditText 
         android:id="@+id/search_text" 
         android:layout_width="fill_parent" 
         android:layout_height="35dp" 
         android:layout_alignParentLeft="true" 
         android:layout_toLeftOf="@+id/btn_search" 
         android:background="@null" 
         android:ems="20" 

         android:imeOptions="actionSearch" 
         android:inputType="text" 
         android:maxLines="1" 
         android:paddingLeft="7dp" 
         android:textColor="@color/njoftime_desc" 
         android:textCursorDrawable="@null" 
         android:textSize="17sp" /> 

       </RelativeLayout> 

       <RelativeLayout 
        android:id="@+id/search_categories_area" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/search_area" 
        android:paddingBottom="7dp" 
        android:paddingTop="13dp"> 


        <GridView 
         android:id="@+id/search_grid" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:layout_centerHorizontal="true" 
         android:drawSelectorOnTop="false" 
         android:horizontalSpacing="2dp" 
         android:numColumns="4" /> 

       </RelativeLayout> 
      </RelativeLayout> 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <com.example.crs.tempus.ExpandableHeightGridView 
        android:id="@+id/njoftime_list" 
        android:layout_width="match_parent" 
        android:horizontalSpacing="5dp" 
        android:verticalSpacing="5dp" 
        android:layout_marginTop="5dp" 
        android:layout_height="wrap_content" 
        android:background="@color/white" 
        android:drawSelectorOnTop="true" 
        android:numColumns="1" /> 


      </RelativeLayout> 
     </LinearLayout> 
    </ScrollView> 

    <RelativeLayout 
     android:id="@+id/left_drawer" 
     android:layout_width="230dp" 
     android:layout_height="fill_parent" 
     android:layout_gravity="start" 
     android:layout_marginTop="?android:attr/actionBarSize" 
     android:background="@color/white" 
     android:orientation="vertical"> 

     <ExpandableListView 
      android:id="@+id/list_slidermenu" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/white" 
      android:choiceMode="singleChoice" 
      android:dividerHeight="1dp" 
      android:drawSelectorOnTop="true" 
      android:groupIndicator="@null" 
      android:paddingBottom="13dp" 
      android:paddingLeft="7dp" 
      android:paddingRight="7dp" 
      android:paddingTop="13dp"></ExpandableListView> 

    </RelativeLayout> 

</android.support.v4.widget.DrawerLayout> 

ExpandableHeightGridView

public class ExpandableHeightGridView extends GridView 
{ 

    boolean expanded = false; 

    public ExpandableHeightGridView(Context context) 
    { 
     super(context); 
    } 

    public ExpandableHeightGridView(Context context, AttributeSet attrs) 
    { 
     super(context, attrs); 
    } 

    public ExpandableHeightGridView(Context context, AttributeSet attrs, 
            int defStyle) 
    { 
     super(context, attrs, defStyle); 
    } 

    public boolean isExpanded() 
    { 
     return expanded; 
    } 

    @Override 
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 
    { 
     // HACK! TAKE THAT ANDROID! 
     if (isExpanded()) 
     { 
      // Calculate entire height by providing a very large height hint. 
      // View.MEASURED_SIZE_MASK represents the largest height possible. 
      int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, 
        MeasureSpec.AT_MOST); 
      super.onMeasure(widthMeasureSpec, expandSpec); 

      ViewGroup.LayoutParams params = getLayoutParams(); 
      params.height = getMeasuredHeight(); 
     } 
     else 
     { 
      super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
     } 
    } 

    public void setExpanded(boolean expanded) 
    { 
     this.expanded = expanded; 
    } 
} 

ExpandableHeightGridView, 다른 활동도 사용되며 작동합니다.

아이디어가 있으십니까? 업데이트]

+0

현재 보이는 모습을 스크린 샷으로 제공해주십시오. –

답변

1

1) ExpandableHeightGridView 클래스에서 onMeasure 재정의 방법 아래의 아래 코드를 사용하십시오. 내 경우 엔 효과가있어. 코드에서

@Override 
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
    int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, 
      MeasureSpec.AT_MOST); 
    super.onMeasure(widthMeasureSpec, expandSpec); 
} 

또는

2) 당신은 ExpandableHeightGridView 클래스의 setExpanded 메서드를 호출하고 true로 설정해야 할 수도 있습니다.

희망이 솔루션 중 하나는 당신을 위해 일할 것입니다.

0

---------은

시도하는 customScollview을 사용하여 다음과 같이 하나의 CustomScrollview을 만들고이

public class CustomScrollView extends ScrollView { 
    public CustomScrollView(Context context) { 
     super(context); 
    } 

    public CustomScrollView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public CustomScrollView(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
    } 

    @TargetApi(Build.VERSION_CODES.LOLLIPOP) 
    public CustomScrollView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 
     super(context, attrs, defStyleAttr, defStyleRes); 
    } 

    @Override 
    public boolean onInterceptTouchEvent(MotionEvent ev) { 
     return false; 
    } 
} 

안드로이드 사용하기 : = "true"를

fillviewport을

<CustomScrollView 
     android:fillviewport="true" 
     android:id="@+id/sv" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/white"> 
처럼, 당신의있는 ScrollView이 추가
+0

나는 그것을 사용하고 그것은 작동하지 않습니다. 위 라인을 추가하지 않으면 GridView가 스크롤되지 않습니다. – Xhulio

+0

plz 내 업데이트 된 답변을 확인하고 알려주세요. –

+0

두 번째 솔루션을 추가하면 GridView 만 스크롤 할 수 있습니다. navigationDrawer를 사용하는 것과 관련이 있는지 여부는 알 수 없습니다. – Xhulio

관련 문제