2013-12-23 7 views
0

저는 안드로이드의 초보자입니다. 코드를 개선 할 수있는 곳에서 의견을 나누고 싶습니다.안드로이드 - GridView가 스크롤되지 않습니다.

우리 프로젝트에서 우리는 런타임에 사용자를로드하는 격자보기를 만들었지 만 이제는이 문제가 때때로 스크롤되지 않으므로 그렇게하기가 어렵습니다.

또한 우리는이 격자보기를 사용하여 응용 프로그램에서 요구하는 상황에 따라보기를 보이고 사라지게했습니다.

<?xml version="1.0" encoding="utf-8"?> 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" > 

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

    <!-- Title Layout --> 

    <RelativeLayout 
     android:id="@+id/newGroupTitleLayout" 
     android:layout_width="match_parent" 
     android:layout_height="50dip" 
     android:background="@drawable/topbar_bg" > 

     <ImageButton 
      android:id="@+id/newGroupCancelButton" 
      android:layout_width="60dip" 
      android:layout_height="30dip" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" 
      android:layout_marginLeft="5dp" 
      android:background="@drawable/buttonanim_cancel_button" 
      android:contentDescription="@string/todo" /> 

     <TextView 
      android:id="@+id/setupPrefTitleTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:text="@string/new_group" 
      android:textColor="@color/yellow" 
      android:textSize="20sp" /> 
    </RelativeLayout> 

    <!-- Group Name --> 

    <LinearLayout 
     android:id="@+id/groupNameLinearLayout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_below="@+id/newGroupTitleLayout" 
     android:layout_marginBottom="5dp" 
     android:layout_marginTop="15dp" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/groupNameTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="15dp" 
      android:text="@string/group_name" 
      android:textColor="@color/yellow" /> 

     <EditText 
      android:id="@+id/groupNameEditText" 
      android:layout_width="match_parent" 
      android:layout_height="35dp" 
      android:layout_marginLeft="15dp" 
      android:layout_marginRight="15dp" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/full_textfield" 
      android:ems="10" 
      android:inputType="text" 
      android:nextFocusRight="@+id/stateEditText" 
      android:paddingLeft="15dp" 
      android:singleLine="true" > 
     </EditText> 
    </LinearLayout> 

    <RelativeLayout 
     android:id="@+id/addMemberLayout" 
     android:layout_width="wrap_content" 
     android:layout_height="290dp" 
     android:layout_below="@+id/groupNameLinearLayout" 
     android:layout_marginLeft="15dp" 
     android:layout_marginRight="15dp" 
     android:layout_marginTop="10dp" 
     android:background="@drawable/membersbox" > 

     <!-- View used when more than 1 member present --> 

     <GridView 
      android:id="@+id/mebersListGridView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:fastScrollAlwaysVisible="true" 
      android:gravity="center" 
      android:numColumns="auto_fit" 
      android:padding="10dp" 
      android:verticalSpacing="10dp" 
      android:visibility="gone" /> 

     <!-- View when there are no members --> 

     <RelativeLayout 
      android:id="@+id/zeroMembersLayout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_centerHorizontal="true" > 

      <ImageButton 
       android:id="@+id/addMemeberImageButton" 
       android:layout_width="90dp" 
       android:layout_height="90dp" 
       android:layout_centerHorizontal="true" 
       android:layout_marginTop="70dp" 
       android:background="@drawable/buttonanim_addmembersmall_button" 
       android:contentDescription="@string/todo" /> 

      <LinearLayout 
       android:id="@+id/memberCountStatementTextViewtLayout" 
       android:layout_width="wrap_content" 
       android:layout_height="25dp" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentRight="true" 
       android:layout_below="@+id/addMemeberImageButton" 
       android:layout_marginTop="10dp" 
       android:gravity="center" 
       android:orientation="horizontal" > 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/this_group_has_" 
        android:textColor="@android:color/white" 
        android:textSize="19sp" /> 

       <TextView 
        android:id="@+id/groupMembersCount" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/_0" 
        android:textColor="@color/yellow" 
        android:textSize="20sp" 
        android:textStyle="bold" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/_members" 
        android:textColor="@android:color/white" 
        android:textSize="19sp" /> 
      </LinearLayout> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/memberCountStatementTextViewtLayout" 
       android:layout_centerHorizontal="true" 
       android:text="@string/tap_to_add_friends" 
       android:textColor="@android:color/white" 
       android:textSize="16sp" /> 
     </RelativeLayout> 
    </RelativeLayout> 

    <!-- Create group button --> 

    <ImageButton 
     android:id="@+id/creategroupbutton" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:layout_below="@+id/addMemberLayout" 
     android:layout_marginBottom="15dp" 
     android:layout_marginLeft="15dp" 
     android:layout_marginRight="15dp" 
     android:layout_marginTop="15dp" 
     android:background="@drawable/buttonanim_creategroup_button" 
     android:contentDescription="@string/todo" /> 
</RelativeLayout></ScrollView> 

이 사람이 나를 도울 수 :

여기 내 XML 파일입니까?

당신의 도움이 감사합니다.

답변

3

스크롤 문제는 GridViewScrollView (사용자의 경우에는 루트 레이아웃)에 넣은 결과입니다. ScrollView은 yout가 자식을 세로로 스크롤 할 수있게합니다. GridView도 세로로 스크롤됩니다. 그래서 다른 해결책을 찾아야합니다. GridView을 사용하면 단점이 있습니다. ListView처럼 머리글과 바닥 글보기가 없습니다. 따라서 GridViewListView으로 바꿀 수도 있습니다.

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; 
}} 



<com.your_package_here.ExpandableHeightGridView 
     android:id="@+id/mebersListGridView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fastScrollAlwaysVisible="true" 
     android:gravity="center" 
     android:numColumns="auto_fit" 
     android:padding="10dp" 
     android:verticalSpacing="10dp" 
     android:visibility="gone" /> 

에서 :

+0

정확하게는 아니지만 그리드보기 자체가 필요합니다. 부모 스크롤 뷰는 화면에서 스크롤 동작을 사용하고 하위 뷰는 스크롤 이벤트를 가져올 수 없으므로 위에서 언급 한 포인트가 옳습니다. 글쎄, 제안 주셔서 감사합니다. – Kailas

+0

ListView를 사용하여 GridView와 거의 비슷한 기능을 수행 할 수 있습니다. GridView의 각 행은 ListView의 단일 하위 노드를 만들 수 있습니다. – GareginSargsyan

0

시도 대신 간단한 GRIDVIEW의 ExpandableHeightGridView를 사용하려면 .. this

0

는 폐쇄있는 ScrollView 태그를 볼 수 없습니다

</ScrollView> 

당신이해야 결코 둥지 목록보기 또는 이 두보기 모두 데이터가보기 영역보다 더 많이 표시되는 즉시 스크롤을 제공하므로 ScrollView 내부의 GridView.

+0

좋은 관찰. 사실, 나는 그것을 잊지 않았다. 불행히도, 당신을 위해 나타나지 않습니다. 내가 볼 수 있도록 내용을 편집했습니다. 귀하의 제안에 감사드립니다. – Kailas

관련 문제