2017-03-02 6 views
0

自分のアクティビティでグリッドビューに投稿されたすべての写真を表示したいと思います。これらは私のコードであり、私は下の写真の結果を持っています。私はグリッドビュー(90dp、90dp)のそれぞれの写真の幅と高さを指定しましたが、フォローはありません。アップロードされたサイズ(横長/縦長)として取り込まれています。また、gridviewの高さをwrap_contentに設定した後でさえ、高さは画像のようにとどまります(約200dpはbかもしれません)。これをどうすれば解決できますか?どこが間違っていたのですか?グリッドビューで同じサイズの写真がすべて必要です。

各写真のモデル:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:layout_width="90dp" 
     android:layout_height="90dp" 
     app:srcCompat="@drawable/post2" 
     android:id="@+id/imageView2" 
     android:scaleType="centerCrop" 
     android:layout_margin="0dp"/> 


</RelativeLayout> 

私のGridViewの別のアクティビティで:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/content_competition_user" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_margin="8dp" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.golstars.www.glostars.competitionUser" 
    tools:showIn="@layout/activity_competition_user"> 

     <GridView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:columnWidth="90dp" 
      android:numColumns="3" 
      android:verticalSpacing="8dp" 
      android:stretchMode="columnWidth" 
      android:horizontalSpacing="8dp" 
      android:id="@+id/competitionusergrid" 
      /> 



</ScrollView> 

マイアダプタ:

それがどのように見えるか
MyUser mUser = MyUser.getmUser(); 
     mUser.setContext(this); 
     Picasso.with(this).load(mUser.getProfilePicURL()).into(profileFAB); 

     targetList = new ArrayList<>(); 

     targetAdapter = new GridAdapter(getApplicationContext(), targetList); 

     competitionusergrid.setAdapter(targetAdapter); 

     String target = ""; 
     target = this.getIntent().getStringExtra("LOAD_TARGET"); 
     System.out.println(target); 

     if(target.equals("COMPETITION")){ 
      //if we have competition pics 
      if(targetList.isEmpty()){ 
       ArrayList<String> aux = this.getIntent().getStringArrayListExtra("COMPETITION_PICS"); 
       System.out.println("target list - " + aux); 
       for(int i = 0; i < aux.size(); i++){ 
        targetList.add(aux.get(i)); 
        targetAdapter.notifyDataSetChanged(); 
       } 


      } 

UI

答えて

0

使用GridView Setup &高さと同じ幅です。

+0

多くの人が気高く!これはまさに私の見方が欲しいのです。 –

0

会社e RecyclerViewの代わりにGridView、RecyclerViewは実装が容易なGridView &と同じです。すべての画像と

enter image description here

+0

あなたはどのようにUIイメージを共有してくださいすることができます見える? – rahul

+0

@rahul申し訳ありませんUIを追加するのを忘れました、私はちょうど確認してくださいでした。 –

+0

@ shakilMahmudShanto RelativeLayoutを使用する必要はありません。これは、あなたがそこで使用している余分な不要なビューの1つのビュー "Model of each picture"です。 ImageViewのみを使用して、それが問題を引き起こしているかどうかを確認してください。イメージビューは90dpに設定されていますが、相対レイアウトはmatch_parentです。それが動作しない場合私に教えてください – rahul

0

あなたが現在のコードを使用したい場合は、次のImageViewのを使用することができ、

public class SquareImageView extends ImageView { 
public SquareImageView(Context context) { 
    super(context); 
} 

public SquareImageView(Context context, AttributeSet attrs) { 
    super(context, attrs); 
} 

public SquareImageView(Context context, AttributeSet attrs, int defStyleAttr) { 
    super(context, attrs, defStyleAttr); 
} 

@Override 
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
    super.onMeasure(widthMeasureSpec, widthMeasureSpec); 
}} 

そして、各項目のレイアウト、

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:srcCompat="@drawable/post2" 
     android:id="@+id/imageView2" 
     android:scaleType="centerCrop" 
     android:layout_margin="0dp"/> 


</RelativeLayout> 
関連する問題