1

私のアプリケーションのホームページには、すべてのセクションの項目のリストを含む異なるセクションがあります。このため私は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に設定する必要があるかもしれません。

このソリューションの1つがうまくいくと思います。

0

アンドロイド、customScollviewを使用し、このように1 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; 
    } 
} 

を使用する---------

試しUPDATED:

fillviewport = "true" を

この

<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

2番目のソリューションを追加すると、GridViewだけがスクロール可能です。私は、navigationDrawerを使用する事実がそれと関係があるかどうかは分かりません。 – Xhulio

関連する問題