2012-03-23 5 views
0

나는 scrollview 안에 GridView가있어 GridView는 (ImageAdapter를 통해) 4 개의 이미지가로드되어있다. 내 문제는 내가 보여주는 이미지 중 3 개를 얻을 수 있지만 4 번째 이미지는 얻을 수 없다는 것입니다. 추가 조사를 통해 gridview의 높이가 행의 높이에 불과하다는 것을 알았습니다. 따라서 XML에서 gridview 높이를 700dp로 설정하면 표시됩니다. 당신이 볼 수 있듯이, 나는의 GridView가 어디 있는지 설명하기 위해 HotPink하기의 GridView의 배경을 설정 한안드로이드 - GridView 최대 높이의 높이

enter image description here

:

여기 스크린 샷입니다.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/llLayoutContainer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" >  

    <!-- <LinearLayout android:id="@+id/llMiddle" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="horizontal"> --> 

     <LinearLayout 
      android:id="@+id/llLeft" 
      android:layout_width="400dp" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:background="@drawable/layout_left" 
      android:paddingLeft="5dp" 
      android:paddingRight="5dp"> 
      <ScrollView 
       android:id="@+id/svMenu" 
       android:layout_width="400dp" 
       android:layout_height="match_parent" 
       > 
      </ScrollView>   
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/llRight" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:orientation="vertical" 
      android:background="@drawable/layout_right" 
      android:padding="0dp"> 
     </LinearLayout> 
    <!-- </LinearLayout> --> 
</LinearLayout> 

있는 LinearLayout "llLeft는"합니다 (있는 ScrollView 내부) 메뉴 항목이로드되는 레이아웃입니다 :

다음은 main_menu에 대한 XML입니다. layout_left는 초록색 배경 주위에 어두운 윤곽선을 그리는 모양 일뿐입니다. 여기

은의 GridView 포함 main_menu_header.xml입니다 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:paddingTop="5dp"> 

    <TextView 
      android:id="@+id/tvDashboardHeader" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text="Dashboard Main Menu" 
      android:textSize="20dp" 
      style="@style/TextShadow" 
      android:paddingTop="5dp" 
      android:gravity="left" 
      android:background="@drawable/menu_item_bg"   
      /> 
    <GridView 
     android:id="@+id/gvMenuItems" 
     android:layout_width="400dp" 
     android:layout_height="match_parent" 
     android:columnWidth="110dp" 
     android:numColumns="auto_fit"  
     android:verticalSpacing="10dp"  
     android:horizontalSpacing="10dp"  
     android:stretchMode="columnWidth" 
     android:background="@color/HotPink" 
     android:gravity="center" > 
    </GridView> 

</LinearLayout> 

을 그리고 여기가의 GridView 채우는 방법은 다음과 같습니다

 ScrollView sv = (ScrollView)findViewById(R.id.svMenu); 
     LayoutInflater liInflater = getLayoutInflater(); 
     ViewGroup vg = (ViewGroup)liInflater.inflate(R.layout.main_menu_header, sv, false); 
     sv.addView(vg); 

     //Setup the Main Menu items on the left side. 
     GridView gvMenuItems = (GridView) findViewById(R.id.gvMenuItems);  
     gvMenuItems.setAdapter(new ImageAdapter(this)); 

ImageAdapter 클래스 :

ImageAdapter 클래스 :

public class ImageAdapter extends BaseAdapter { 
    private Context mContext;  

    public ImageAdapter(Context c) { 
     mContext = c;  
    }  

    public int getCount() {   
     return mThumbIds.length;  
    }  

    public Object getItem(int position) {   
     return null;  
    }  

    public long getItemId(int position) {   
     return 0;  
    }  

    // create a new ImageView for each item referenced by the Adapter  
    public View getView(int position, View convertView, ViewGroup parent) {   

     ImageView imageView; 

     if (convertView == null) { 
      // if it's not recycled, initialize some attributes    
      imageView = new ImageView(mContext); 
      imageView.setLayoutParams(new GridView.LayoutParams(parent.getLayoutParams().width, 125)); //new GridView.LayoutParams(400, 125));    
      //imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); 
      imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 
      imageView.setMaxHeight(50); 
      imageView.setMaxWidth(50); 
      //imageView.setPadding(30, 0, 0, 0); 
      //imageView.setPadding(40, 30, 20, 30); 

      } else {    
       imageView = (ImageView) convertView;   
      }   

     imageView.setImageResource(mThumbIds[position]); 

     return imageView; 
    }  

    // references to our images  
    private Integer[] mThumbIds = { 
      R.drawable.home, 
      R.drawable.open_folder, 
      R.drawable.paper_pen, 
      R.drawable.person 
    }; 
} 

안드로이드 : layout_height = "match_parent"의 gridview 속성이 작동한다고 생각했지만 그렇지 않았습니다. GridView가 scrollview 내부에서 왼쪽 전체를 차지할 수있는 방법에 대한 아이디어가 있습니까?

답변

1

가장 좋은 추측은 scrollview이 문제를 일으키는 것입니다.

scrollview이 필요합니까?

격자보기가 스크롤을 처리합니다. 중복되는 것 같습니다. 따라서 제거하고 직접 부풀려진보기를 llLeft에 직접 추가하십시오. 그것은 문제를 해결할 것입니다.


사실, xml을 사용하여 UI 문제를 해결하는 것이 더 우아 할 것입니다. main_menu.xml<include> 태그를 사용하십시오. 여기에

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/llLayoutContainer" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="horizontal" >  

<!-- <LinearLayout android:id="@+id/llMiddle" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:orientation="horizontal"> --> 

    <LinearLayout 
     android:id="@+id/llLeft" 
     android:layout_width="400dp" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:background="@drawable/layout_left" 
     android:paddingLeft="5dp" 
     android:paddingRight="5dp"> 
     <include 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     layout="@layout/main_menu_header" />   
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/llRight" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="vertical" 
     android:background="@drawable/layout_right" 
     android:padding="0dp"> 
    </LinearLayout> 
<!-- </LinearLayout> --> 

+0

당신 말이 맞아 ...있는 ScrollView가 XML로 변경 한 후, 난 그냥 ImageAdapter에있는 gridview 어댑터를 설정하는 .... 중복 어떻게? 나는 이것을 시도했지만 아무 것도 나타나지 않는다. ImageAdapter가 뷰를 팽창시키지 않지만 너무 확신 할 수 없기 때문에 나는 추측하고있다. 내 뇌는 약간 쓰레기통입니다. 직접 뷰를 팽창 시키려면 어떻게해야합니까? – Robert

+0

내가 제안한 xml을 따르고 있다면 질문에 마지막 두 줄의 코드 만 사용해야합니다. // 왼쪽의 기본 메뉴 항목을 설정합니다. GridView gvMenuItems = (GridView) findViewById (R.id.gvMenuItems); gvMenuItems.setAdapter (새 ImageAdapter (this)); – PH7

+0

옛날 방식으로 시도해 볼 수 있습니다. 스크롤보기를 제거하면됩니다. 그것도 작동해야합니다. – PH7