更改RelativeLayout高度,因为用户在滚动视图中滚动
问题描述:
我试图改变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();
这是它的外观
如果你有更好的想法如何收缩的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>
答
您需要将您的RelativeLayout
的ScrollView
内,并再次尝试setTranslationY
- 它应该工作
+0
我试过这种方法,它的工作原理,它只是需要很多调整,使其看起来如何我想:)谢谢你的支持 – Bartando
你可以分享你的布局XML文件是正确的? – Alex
是的,它在现在的主帖:) – Bartando
你想调整整个'collapsing.view'或试图添加视差效果图像? – Alex