2016-06-14 3 views
1

기본적으로 paralax 섹션에 imageview가있는 collapsingToolbarLayout이 있습니다. 이 이미지는 정사각형이 될 것이므로 전체 이미지를 표시하고자하므로 collapsingToolbarLayout의 높이를 너비와 같게 설정해야합니다. 이것을 어떻게 할 수 있습니까? 어떤 이유로 imageView 및 coordinatorlayout의 wrap_content가 내용을 실제로 랩핑하지 않습니다. Glide를 사용하여 네트워크 리소스에서 이미지를로드하므로 활동이 시작될 때 이미지가 없습니다.collapsingToolbarLayout 높이 프로그래밍 방식으로 설정

현재 레이아웃 :

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/coordinatorLayout" 
    android:fitsSystemWindows="true"> 
    <android.support.design.widget.AppBarLayout 
     android:id="@+id/main_appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     android:fitsSystemWindows="true"> 
     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/main_collapsing" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleMarginStart="140dp" 
      app:expandedTitleMarginBottom="90dp" 
      app:expandedTitleMarginEnd="64dp"> 
      <ImageView 
       app:layout_collapseMode="parallax" 
       android:id="@+id/icon" 
       android:transitionName="pic" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:scaleType="centerCrop" 
       android:fitsSystemWindows="true"/> 
      <FrameLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_marginBottom="20dp" 
       app:layout_collapseMode="parallax"> 
       <LinearLayout 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="bottom" 
        android:padding="20dp" 
        android:orientation="horizontal"> 
        <ImageView 
         android:layout_width="100dp" 
         android:layout_height="100dp" 
         android:id="@+id/smallicon"/> 
        <LinearLayout 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:orientation="vertical" 
         android:layout_gravity="bottom" 
         android:padding="20dp"> 
         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:id="@+id/artist" 
          android:ellipsize="end" 
          android:singleLine="true" 
          android:textSize="24sp"/> 
         <TextView 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:ellipsize="end" 
          android:singleLine="true" 
          android:id="@+id/date"/> 
        </LinearLayout> 
       </LinearLayout> 
      </FrameLayout> 
      <android.support.v7.widget.Toolbar 
       android:id="@+id/main_toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
       app:layout_collapseMode="pin"/> 
     </android.support.design.widget.CollapsingToolbarLayout> 
    </android.support.design.widget.AppBarLayout> 
    <android.support.v7.widget.RecyclerView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     android:id="@+id/list" 
     android:dividerHeight="2dp" 
     android:transitionName="bottom"> 
    </android.support.v7.widget.RecyclerView> 
</android.support.design.widget.CoordinatorLayout> 
+0

같이 findViewById (R.id.coordinatorLayout)'와 시작'당신은 내가 '디스플레이 표시를하고 시도 CoordinatorLayout.LayoutParams' –

+0

'주위에 뭔가 = getWindowManager()를 사용할 수있는 경우 다음을 참조 getDefaultDisplay().; 포인트 크기 = 새 포인트(); display.getSize (size); collapsingToolbarLayout.setLayoutParams (new ViewGroup.LayoutParams (size.x, size.x)); ' 그러나 그 중 하나가 작동하지 않습니다 – Timestretch

+0

뷰를 0 너비 및 높이로 설정하지 않겠습니까? –

답변

2

사실, 당신은 아마 당신의 ImageViewandroid:adjustViewBounds="true"을 추가 할 수 있습니다. 기준 : documentation of adjustViewBounds

ImageView에서 드로어 블의 종횡비를 유지하도록 경계를 조정하려면이 값을 true로 설정하십시오.

기본값 (false)으로두면 글라이드가 나중에 이미지를로드 할 때 ImageView의 크기가 조정되지 않습니다.

관련 문제