내 응용 프로그램의 홈페이지에 모든 섹션의 항목 목록이 포함 된 다른 섹션이 있어야합니다. 이를 위해 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, 다른 활동도 사용되며 작동합니다.
아이디어가 있으십니까? 업데이트]
현재 보이는 모습을 스크린 샷으로 제공해주십시오. –