2016-04-24 29 views
1

我試圖改變RelativeLayout作爲用戶滾動的高度,所以它順利地向上移動。這是有點工作,但它的閃爍和閃爍。更改RelativeLayout高度,因爲用戶在滾動視圖中滾動

我試圖使用setTranslationY,但不會使用RelativeLayout移動滾動視圖。

int top = mScrollView.getScrollY(); 
int maxRelative = formulas.dpToPx(250); 
int actualRelative = (int)((1.0-((float)top)/300.0)*((float)maxRelative)); 
RelativeLayout.LayoutParams layout_description = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 
          actualRelative); 
mCollapsingLayout.setLayoutParams(layout_description); 
        mCollapsingLayout.requestLayout(); 

這是它的外觀

http://imgur.com/7PL6Yt5

如果你有更好的想法如何收縮的RelativeLayout爲您滾動,它的讚賞。

編輯:這是我的XML

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/app_bar_height" 
    android:id="@+id/collapsing.view"> 

    <ImageView 
     android:id="@+id/collapsing.view.image" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:src="@drawable/theflash" 
     android:tint="#7F000000" 
     android:scaleType="centerCrop"/> 
    <ImageButton 
     android:id="@+id/favorite.button" 
     android:layout_width="70dp" 
     android:layout_height="70dp" 
     android:background="?android:attr/selectableItemBackground" 
     android:scaleType="fitCenter" 
     android:layout_centerHorizontal="true" 
     android:layout_alignParentBottom="true" 
     android:layout_marginBottom="30dp" 
     android:src="@drawable/favorite_button" 
     /> 
    <FrameLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:paddingBottom="30px"> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="The Flash" 
      android:textColor="#fff" 
      android:textSize="25sp" 
      android:layout_centerInParent="true" 
      /> 
    </FrameLayout> 
</RelativeLayout> 

<ScrollView 
    android:id="@+id/detail.scrollview" 
    android:layout_below="@+id/collapsing.view" 
    android:layout_width="match_parent" 
    android:fillViewport="true" 
    android:layout_height="match_parent"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 
</LinearLayout> 
</ScrollView> 
+0

你可以分享你的佈局XML文件是正確的? – Alex

+0

是的,它在現在的主帖:) – Bartando

+0

你想調整整個'collapsing.view'或試圖添加視差效果圖像? – Alex

回答

1

您需要將您的RelativeLayoutScrollView內,並再次嘗試setTranslationY - 它應該工作

+0

我試過這種方法,它的工作原理,它只是需要很多調整,使其看起來如何我想:)謝謝你的支持 – Bartando

1

有幾種方法來此,包括現成的類,如this one它基本上做你想要的。您可能需要刪除部分的收縮文本等等,但在你需要它

enter image description here

+0

這正是我需要的,我不想要使用Appcompats CollapsingToolbar,因爲它涉及到定製。我會試着深入一點。謝謝 :) – Bartando

相關問題