2017-02-20 13 views
0

最近、いくつかの人気のAndroidライブラリで遊んでいます。私はStaggeredGridLayout & Frescoのヘルプが必要です。Image height stretched(SimpleDraweeView)

私は、Java経由/ XMLでlayout_heightのparamsを変更しようとしましたが、私は良い結果を得ていないよ。私は私が間違って

As you can see, these images height is streched

を得ているものをお見せしましょう

Everything is up on my Github repo

一部抜粋

public class GiphyView 
    extends RecyclerView 
    implements GiphyPresenter.ViewBind { 

@Inject 
public GiphyPresenter mGiphyPresenter; 

private GiphyAdapter mAdapter; 

public GiphyView(Context context) { 
    super(context); 
    initView(context); 
} 

public GiphyView(Context context, @Nullable AttributeSet attrs) { 
    super(context, attrs); 
    initView(context); 
} 

public GiphyView(Context context, @Nullable AttributeSet attrs, int defStyle) { 
    super(context, attrs, defStyle); 
    initView(context); 
} 

private void initView(Context context) { 
    CustomApplication.get(context).getGiphyComponent().inject(this); 

    mAdapter = new GiphyAdapter(); 
    setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)); 
    setAdapter(mAdapter); 
} 

@Override 
protected void onAttachedToWindow() { 
    super.onAttachedToWindow(); 
    mGiphyPresenter.attachVu(this); 
} 

@Override 
protected void onDetachedFromWindow() { 
    ImagePipeline imagePipeline = Fresco.getImagePipeline(); 
    imagePipeline.clearCaches(); 

    mGiphyPresenter.detachVu(); 

    super.onDetachedFromWindow(); 
} 

@Override 
public void notifyRangeInserted(int start, int count) { 
    mAdapter.notifyItemRangeInserted(start, count); 
} 

private class GiphyAdapter extends RecyclerView.Adapter<GiphyViewHolder> { 
    @Override 
    public GiphyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
     return new GiphyViewHolder(
       LayoutInflater.from(parent.getContext()) 
         .inflate(R.layout.giphy_cell, parent, false)); 
    } 

    @Override 
    public void onBindViewHolder(GiphyViewHolder holder, int position) { 
     holder.setGif(mGiphyPresenter.getItemImage(position)); 
    } 

    @Override 
    public int getItemCount() { 
     return mGiphyPresenter.getSize(); 
    } 
} 

class GiphyViewHolder extends ViewHolder { 
    @BindView(R.id.gif) 
    SimpleDraweeView mGif; 

    GiphyViewHolder(View itemView) { 
     super(itemView); 
     ButterKnife.bind(this, itemView); 
    } 

    void setGif(String url) { 
     /*ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url)) 
       .setRotationOptions(RotationOptions.autoRotate()) 
       .setLowestPermittedRequestLevel(ENCODED_MEMORY_CACHE) 
       .build();*/ 

     DraweeController controller = Fresco.newDraweeControllerBuilder() 
       .setUri(url) 
       .setAutoPlayAnimations(true) 
       //.setImageRequest(request) 
       .build(); 
     mGif.setController(controller); 
    } 
} 

}

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:fresco="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 

<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/card_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    card_view:cardCornerRadius="6dp" 
    card_view:cardUseCompatPadding="true"> 

    <!-- 4:3 aspect ratio 
      fresco:viewAspectRatio="1.33" --> 
    <com.facebook.drawee.view.SimpleDraweeView 
     android:id="@+id/gif" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     fresco:failureImage="@drawable/ic_error_black_24dp" 
     fresco:placeholderImage="@drawable/ic_android_black_24dp"/> 
</android.support.v7.widget.CardView> 

PSA:私はすでに、はい(wrap_contentで遊んしようとしたが、運を持っていないしました私はフレスコがそれをサポートしていないことを知っている)。

+0

あなたが達成したいと思いますか? –

+0

layout_height = "wrap_content"であっても、このスクリーンショットで見ることができるように(http://i.imgur.com/JWXc9Jz.png)、イメージの「スタック」を取得したいと考えています。fresco:viewAspectRatio = "1.33"、すべてのCardviewの間に長いスペースがあります – MaccheroniCoding

答えて

0

親カードビューのサイズをwrap_contentに設定する必要があります。親は不要ですLinearLayout。ちょうどのようなものを使用します。

<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/card_view" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    card_view:cardCornerRadius="6dp" 
    card_view:cardUseCompatPadding="true"> 

    <com.facebook.fresco.SimpleDraweeView ... /> 
</android.support.v7.widget.CardView> 

を私はここでグリッドレイアウトを持つリサイクルビューでCardViewを使用する方法を示したサンプルアプリを追加しました:https://github.com/facebook/fresco/blob/master/samples/showcase/src/main/java/com/facebook/fresco/samples/showcase/drawee/DraweeRecyclerViewFragment.java

+0

ありがとう、私はすでに試してみました。フレスコ画はラップコンテンツをサポートしていないので、layout_width = "wrap_content"の設定は機能しません(4:3ビューを指定して追加します) – MaccheroniCoding

+0

ラップコンテンツを使用して保持するために親 'CardView'を変更する必要がありますmatch_parentとアスペクト比を持つDraweeビュー。 –

+0

[あなたの設定でこれを得る](http://i.imgur.com/3TWV6fe.png)、cardViewなしで[これらのスペース](https://imgur.com/JWXc9Jz) – MaccheroniCoding