如何自动滚动动画布局

carvr3hs  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(281)

我有一个动画线性布局,我想自动滚动,我希望布局平稳地向下滚动到底部,但问题是,自动滚动最初推动了父视图的布局,然后再向下滚动布局。我用动画一个接一个地显示布局。
这是我的xml

<?XML version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/red/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android: layout_marginTop="10dp"
android:paddingBottom="10dp">

<RelativeLayout
android:id="@+id/LayoutAll"
android:layout_width="550dp"
android:layout_height="180dp"
android:paddingRight="20dp"
android:paddingBottom="10dp"
android:paddingLeft="20dp">

<ScrollView
android:id="@+id/Scroll"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:id="@+id/LayoutParent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout
android:id="@+id/Layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item One"
android:layout_gravity="start"
android:gravity="start">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item One Price"
android:layout_gravity="end"
android:gravity="end">

</LinearLayout>

<LinearLayout
android:id="@+id/Layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item Two"
android:layout_gravity="start"
android:gravity="start">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item Two Price"
android:layout_gravity="end"
android:gravity="end">

</LinearLayout>

<LinearLayout
android:id="@+id/Layout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item Three"
android:layout_gravity="start"
android:gravity="start">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item Three Price"
android:layout_gravity="end"
android:gravity="end">

</LinearLayout>

<LinearLayout
android:id="@+id/Layout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item Four"
android:layout_gravity="start"
android:gravity="start">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item Four Price"
android:layout_gravity="end"
android:gravity="end">

</LinearLayout>

<LinearLayout
android:id="@+id/Layout5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item Five"
android:layout_gravity="start"
android:gravity="start">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item Five Price"
android:layout_gravity="end"
android:gravity="end">

</LinearLayout>
<LinearLayout
android:id="@+id/Layout6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item Six"
android:layout_gravity="start"
android:gravity="start">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item Six Price"
android:layout_gravity="end"
android:gravity="end">

</LinearLayout>

<LinearLayout
android:id="@+id/Layout7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item Seven"
android:layout_gravity="start"
android:gravity="start">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item Seven Price"
android:layout_gravity="end"
android:gravity="end">

</LinearLayout>

<LinearLayout
android:id="@+id/Layout8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item Eight"
android:layout_gravity="start"
android:gravity="start">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item Eight Price"
android:layout_gravity="end"
android:gravity="end">

</LinearLayout>

<LinearLayout
android:id="@+id/Layout9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item Nine"
android:layout_gravity="start"
android:gravity="start">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item Nine Price"
android:layout_gravity="end"
android:gravity="end">

</LinearLayout>

<LinearLayout
android:id="@+id/Layout10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item Ten"
android:layout_gravity="start"
android:gravity="start">

<TextView
android:layout_width="0dp"
android: layout_weight="1"
android:layout_height="match_parent"
android:text="Item Ten Price"
android:layout_gravity="end"
android:gravity="end">

</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
</LinearLayout>

主活动.java

import android.app.Dialog;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.ScrollView;

Public class ScrollItems extends Dialog{

private long Delay_Scroll = 1000;
private Activity main_Activity;
LinearLayout Layout_1,Layout_2,Layout_3,Layout_4,Layout_5,Layout_6,Layout_7,Layout_8,Layout_9,Layout_10;

public ScrollItems (Activity cons_Activity){

super(cons_Activity);
this.main_Activity = cons_Activity;
}

@Overtide
protected void onCreate(Bundle saveInstanceState){

super.onCreate(saveInstanceState);
setContentView(R.layout. activity_scroll_items);

AnimateLayout();
}

public void AnimateLayout(){

int [] LayoutIds = {R.id.Layout1,R.id.Layout2,R.id.Layout3,R.id.Layout4,R.id.Layout5,R.id.Layout6,R.id.Layout7,R.id.Layout8,R.id.Layout9,R.id.Layout10};

int LayoutCount = 1;
for(int viewId : LayoutIds) {

Animation animation = AnimationUtills.loadAnimation(this.main_Activity, R.anim.animate);
animation.setStartOffset(LayoutCount * 500);
int Layout_ID = LayoutIds [LayoutCount - 1];
LinearLayout layout = (LinearLayout) findViewById(Layout_ID);
layout.setAnimation(animation);
LayoutCount ++;
}
ScrollView scrollView = (ScrollView) findViewById(R.id.Scroll);
scrollView.postDelay(new Runnable (){
@Override
public void run (){
scrollView.fullScroll(ScrollView.FOCUS.DOWN);
}
},Delay_Scroll);
}}

动画.xml

<alpha
xmlns:android="http://schemas.android.com/apk/red/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromAlpha="0.0"
android:toAlpha="2"
android:duration="500"/>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题