我正在尝试随着用户滚动来更改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>
有几种方法来此,包括现成的类,比如这一次基本上你想要做什么。您可能需要删除用于缩小文本的部分,依此类推,但这正是您需要的地方
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句