为 ScrollView 实现指示性运动以显示文本预览
Implementing Instructive Motion For ScrollView To Show a Text Preview
最近开始在developer.android.com上看'Android Material Design'视频课程
在第 4 课 Meaningful Motion 中有一个名为 Implementing Instructive Motion 的视频。我试图实现与下图相同的输出:
这是我到目前为止所做的:
在MainActivity.java中:
public void onEnterAnimationComplete() {
super.onEnterAnimationComplete();
Animator animator = ObjectAnimator.ofInt(mScrollView,"scrollY",300).setDuration(400);
animator.start();
}
在activity_main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:id="@+id/full_image_view"
android:layout_width="match_parent"
android:layout_height="300dp"
android:scaleType="centerInside"
/>
<ScrollView
android:id="@+id/mScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="300dp"
android:layout_below="@+id/full_image_view"
android:elevation="8dp"
>
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/full_image_view"
android:fontFamily="sans-serif-condensed"
android:textSize="20sp"
android:elevation="8dp"
android:text="@string/sample_big_text"/>
</ScrollView>
</FrameLayout>
我的问题是为什么输出不同?
任何帮助将不胜感激。
首先,给TextView设置一个足够长的字符串。
其次,将android:clipToPadding="false"
添加到ScrollView。
(可选)在 ScrollView 中,添加包含 TextView 的白色背景 LinearLayout。
最近开始在developer.android.com上看'Android Material Design'视频课程
在第 4 课 Meaningful Motion 中有一个名为 Implementing Instructive Motion 的视频。我试图实现与下图相同的输出:
这是我到目前为止所做的:
在MainActivity.java中:
public void onEnterAnimationComplete() {
super.onEnterAnimationComplete();
Animator animator = ObjectAnimator.ofInt(mScrollView,"scrollY",300).setDuration(400);
animator.start();
}
在activity_main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:id="@+id/full_image_view"
android:layout_width="match_parent"
android:layout_height="300dp"
android:scaleType="centerInside"
/>
<ScrollView
android:id="@+id/mScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="300dp"
android:layout_below="@+id/full_image_view"
android:elevation="8dp"
>
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/full_image_view"
android:fontFamily="sans-serif-condensed"
android:textSize="20sp"
android:elevation="8dp"
android:text="@string/sample_big_text"/>
</ScrollView>
</FrameLayout>
我的问题是为什么输出不同? 任何帮助将不胜感激。
首先,给TextView设置一个足够长的字符串。
其次,将android:clipToPadding="false"
添加到ScrollView。
(可选)在 ScrollView 中,添加包含 TextView 的白色背景 LinearLayout。