2017-02-20 1 views
0

최근에 인기있는 안드로이드 라이브러리로 놀고 있는데, StaggeredGridLayout & 프레스코로 도움이 필요합니다.Image height stretched (SimpleDraweeView)

내가 자바를 통해/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)에서 볼 수있는 것처럼 "스택"이미지를 얻고 싶습니다. 프레스코 : 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

응답 해 주셔서 감사합니다.하지만 이미 시도했습니다. Fresco는 랩 콘텐츠를 지원하지 않으므로 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