2014-07-06 42 views
0

Result.java:的GridView未示出所有的數據

Fragment f = new GridViewFragement(); 
FragmentManager fm = getFragmentManager(); 

fm.beginTransaction().replace(R.id.grid, f).commit(); 

Activity_result.xml:

<LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:id="@+id/grid" 
     android:orientation="vertical" 

    > 


</LinearLayout> 

Row_grid.xml:限定了網格項

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

    <ImageView 

    android:id="@+id/item_image" 
    android:layout_width="50dp" 
    android:layout_height="50dp" 
    android:layout_marginRight="10dp" 
    android:src="@drawable/home" > 
</ImageView> 

<TextView 
    android:id="@+id/item_text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="5dp" 
    android:textSize="15sp" > 
</TextView> 

</LinearLayout> 

grid.xml:

 <GridView 
    android:id="@+id/gridView1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_margin="4dp" 
    android:columnWidth="80dp" 
    android:gravity="center" 
    android:numColumns="auto_fit" 
    android:stretchMode="columnWidth" 
    android:fadeScrollbars="false" 
    /> 

On create in grid view fragement: 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    // on create for activity 


    View view = inflater.inflate(R.layout.grid, container, false); 
    Bitmap homeIcon = BitmapFactory.decodeResource 
    (this.getResources(), R.drawable.home); 
    Bitmap userIcon = BitmapFactory.decodeResource 
    (this.getResources(), R.drawable.personal); 
    // 
    gridArray.add(new Item(homeIcon,"Home")); 
    gridArray.add(new Item(userIcon,"Personal")); 
    gridArray.add(new Item(homeIcon,"Home")); 
    gridArray.add(new Item(userIcon,"User")); 
    gridArray.add(new Item(homeIcon,"Building")); 
    gridArray.add(new Item(userIcon,"User")); 
    gridArray.add(new Item(homeIcon,"Home")); 
    gridArray.add(new Item(userIcon,"xyz")); 
    gridArray.add(new Item(homeIcon,"Home")); 
    gridArray.add(new Item(userIcon,"User")); 
    gridArray.add(new Item(homeIcon,"House")); 
    gridArray.add(new Item(userIcon,"Friend")); 



    gridView = (GridView) view.findViewById(R.id.gridView1); 
    customGridAdapter =newCustomGridViewAdapter 
    (view.getContext(),R.layout.row_grid,gridArray); 

    gridView.setAdapter(customGridAdapter); 

    return view; 
} 

試圖顯示我的GridView的所有數據的問題。它只在中途切斷,前三個項目連續顯示。對不起我無法發佈圖片,因爲我只有代表1. 我試圖把scrollviews和滾動條出現,但它只是不會滾動或顯示其所有數據

回答

1

如果你想看到所有你需要的行設置layout_height = fill_parent 不是layout_width = fill_parent和layout_height = wrap_content。它不會是 能夠顯示所有行,除非您根據您擁有的單元格數量將它們全部設置爲非常小的 。如果你有很多單元格 ,那麼甚至試圖讓它們出現在一個屏幕上是毫無意義的。

我的建議是去列表視圖。

+1

真的好建議男人生病了試一試 – user3809087

+1

好吧,一切順利:) – jasim

相關問題