我對我的四個TextView
使用滑動向上/向下動畫。以下是我的XML向上/向下滑動後的動畫Textview onClickListener不起作用
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shadow"
android:orientation="vertical"
android:weightSum="2.0" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0" >
<TextView
android:id="@+id/textViewblue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_marginLeft="25dp"
android:background="@drawable/blue"
android:gravity="center"
android:text="blue" />
<TextView
android:id="@+id/textVieworange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:layout_marginRight="25dp"
android:background="@drawable/orange"
android:gravity="center"
android:text="orange" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0">
<TextView
android:id="@+id/textViewpink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="25dp"
android:background="@drawable/pink"
android:gravity="center"
android:text="pink" />
<TextView
android:id="@+id/textViewgreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:layout_marginRight="25dp"
android:background="@drawable/green"
android:gravity="center"
android:text="green" />
</RelativeLayout>
</LinearLayout>
和以下是我的課
public class HomeScreenActivity extends Activity implements OnClickListener {
TextView textViewblue, textVieworange, textViewpink,
textViewgreen;
Animation mAnimation_up, mAnimation_down;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_screen);
mAnimation_up = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_SELF, 0f,
TranslateAnimation.RELATIVE_TO_SELF, 0f,
TranslateAnimation.RELATIVE_TO_SELF, 1.6f,
TranslateAnimation.RELATIVE_TO_SELF, 0f);
mAnimation_up.setDuration(1000);
mAnimation_up.setRepeatCount(-1);
mAnimation_up.setRepeatMode(Animation.REVERSE);
mAnimation_up.setInterpolator(new LinearInterpolator());
mAnimation_down = new TranslateAnimation(
TranslateAnimation.RELATIVE_TO_SELF, 0f,
TranslateAnimation.RELATIVE_TO_SELF, 0f,
TranslateAnimation.RELATIVE_TO_SELF, 0f,
TranslateAnimation.RELATIVE_TO_SELF, 1.6f);
mAnimation_down.setDuration(1000);
mAnimation_down.setRepeatCount(-1);
mAnimation_down.setRepeatMode(Animation.REVERSE);
mAnimation_down.setInterpolator(new LinearInterpolator());
initialize();
}
private void initialize() {
textViewblue = (TextView) findViewById(R.id.textViewblue);
textVieworange = (TextView) findViewById(R.id.textVieworange);
textViewpink = (TextView) findViewById(R.id.textViewpink);
textViewgreen = (TextView) findViewById(R.id.textViewgreen);
textViewblue .setOnClickListener(this);
textVieworange .setOnClickListener(this);
textViewpink .setOnClickListener(this);
textViewgreen .setOnClickListener(this);
textViewblue .setAnimation(mAnimation_down);
textViewpink .setAnimation(mAnimation_down);
textVieworange .setAnimation(mAnimation_up);
textViewgreen .setAnimation(mAnimation_up);
}
@Override
public void onClick(View v) {
Intent intentmenu;
switch (v.getId()) {
case R.id.textViewblue:
Toast.makeText(this, "blue", Toast.LENGTH_LONG).show();
break;
case R.id.textVieworange:
Toast.makeText(this, "orange", Toast.LENGTH_LONG).show();
break;
case R.id.textViewpink:
Toast.makeText(this, "pink", Toast.LENGTH_LONG).show();
break;
case R.id.textViewgreen:
Toast.makeText(this, "reeng", Toast.LENGTH_LONG).show();
break;
}
}
}
的問題是,當在動畫僅在其XML位置開始onClickListener
作品INT位置任意TextView
滑動裝置而不是更新的位置。 請給我建議解決方案,我如何檢測更新後的位置以檢測TextView
上的onClickListener。
謝謝。
感謝您的建議,你可以給我任何簡單的參考鏈接 – Akshay 2014-09-09 06:25:17
看到http://android-developers.blogspot.com/2011/05/introducing-viewpropertyanimator.html – suitianshi 2014-09-09 06:30:40
再次感謝... – Akshay 2014-09-09 06:32:51