2014-03-06 41 views
1

我覺得這是我的適配器問題所在,它的工作在一個正常的GridView,我以爲我只想能夠切換雙向-gridview的到位GridView的麻煩。但現在顯示了一個沒有使用任何東西的地方,另一個地方的圖片不能垂直填充視圖,並且列數比我設置的多。有實現雙向-gridview的

這裏的適配器代碼:

public final class CoverGridViewAdapter extends BaseAdapter { 
    private final Context context; 
    private final List<String> urls = new ArrayList<String>(); 
    private final ArrayList<HashMap<String,String>> arrayList; 

public CoverGridViewAdapter(Context context, ArrayList<HashMap<String, String>> arrayList) { 
    this.context = context; 
    this.arrayList = arrayList; 
} 

@Override public View getView(int position, View convertView, ViewGroup parent) { 
    // Get the image URL for the current position. 
    //String url = getItem(position); 
    final HashMap<String,String> game = getItem(position); 

    CoverImageView view = (CoverImageView) convertView; 
    if (view == null) { 
     view = new CoverImageView(context); 
     view.setScaleType(CENTER_CROP); 
     view.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       Intent myIntent = new Intent(context, GameActivity.class); 
       myIntent.putExtra("key", game); //Optional parameters 
       context.startActivity(myIntent); 

      } 
     }); 
    } 



    // Trigger the download of the URL asynchronously into the image view. 
    Picasso.with(context) // 
      .load(game.get(GameDiscoveryFragment.TAG_SUPER_IMAGE)) // 
      .placeholder(R.drawable.ic_launcher) //TODO: placeholder image 
      .error(R.drawable.ic_launcher) //TODO: error image 
      .fit() // 
      .into(view); 

    return view; 
} 

@Override public int getCount() { 
    return arrayList.size(); 
} 

@Override public HashMap<String,String> getItem(int position) { 
    //return urls.get(position); 
    return arrayList.get(position); 
} 

@Override public long getItemId(int position) { 
    return position; 
} 

而到了GitHub的項目https://github.com/jess-anders/two-way-gridview

編輯鏈接:多一點點信息。我多玩了一會兒,雖然沒有圖像以縱向顯示,但是當我旋轉設備時它們確實出現。所以也許這個xml也會有所幫助。

<com.ryanjohnstone.gamediscovery.app.com.jess.ui.TwoWayGridView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:background="#E8E8E8" 
     android:id="@+id/similar_games_grid_view" 
     android:layout_width="fill_parent" 
     android:layout_height="115dp" 
     app:cacheColorHint="#E8E8E8" 
     app:rowHeight="80dp" 
     app:numColumns="@integer/similar_column_count" 
     app:numRows="1" 
     app:verticalSpacing="1dp" 
     app:horizontalSpacing="1dp" 
     app:stretchMode="spacingWidthUniform" 
     app:scrollDirectionPortrait="horizontal" 
     app:scrollDirectionLandscape="horizontal" 
     app:gravity="center" 
     android:layout_gravity="center_horizontal|bottom" /> 

編輯2:沒有任何東西在縱向顯示的原因是我需要設置columnWidth屬性。當我設置了列數時,我不明白爲什麼這是必需的。在GridView上不需要。有沒有辦法在XML中設置值的屏幕寬度除以列數?

編輯3:設置應用程序:stretchMode到columnWidth時已經固定在縱向模式的問題,我現在看到的圖像和他們填寫自己的行和列。我仍然有一個問題,他們沒有填補他們的風景。下面是當前xml:

<com.ryanjohnstone.gamediscovery.app.com.jess.ui.TwoWayGridView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:background="#E8E8E8" 
     android:id="@+id/grid_view" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     app:cacheColorHint="#E8E8E8" 
     app:numColumns= "@integer/column_count" 
     app:numRows="auto_fit" 
     app:verticalSpacing="1dp" 
     app:horizontalSpacing="1dp" 
     app:stretchMode="columnWidth" 
     app:scrollDirectionPortrait="vertical" 
     app:scrollDirectionLandscape="horizontal" 
     app:gravity="center"/> 

編輯4:爲了澄清,它的工作如預期與垂直滾動畫像。水平滾動的肖像不工作,我想如何。它顯示所有圖像,而不是我放入numColumns中的數字。

編輯5:我複製並粘貼我的XML到git的樞紐工程的示例應用程序和它的作品如預期,所以我回到我相信問題在於我的適配器中。

+0

解決了這個也許你鏈接到你使用雙向GridView控件源(我猜GitHub的項目?) – WarrenFaith

+0

哦,是的,對不起。通過該項目的鏈接編輯該問題。 – RyanJohnstone

回答

0

xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:background="#E8E8E8" 
android:id="@+id/gridview" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
app:cacheColorHint="#E8E8E8" 

app:numColumns="auto_fit" 
app:numRows="1" 

app:stretchMode="columnWidth" 
app:scrollDirectionPortrait="vertical" 
app:scrollDirectionLandscape="horizontal" 
app:gravity="center"