如何在android中从左向右滑动组件
我尝试在布局文件中滑动组件。我尝试以不同的方式执行。但这对我不起作用。这里有一些我曾经做过的事情如何在android中从左向右滑动组件,android,ontouchlistener,gesturedetector,ontouch,Android,Ontouchlistener,Gesturedetector,Ontouch,我尝试在布局文件中滑动组件。我尝试以不同的方式执行。但这对我不起作用。这里有一些我曾经做过的事情 LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout options_layout = (LinearLayout) findViewById(R.id.linearLayout); for(int i=0;i<5;i
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout options_layout = (LinearLayout) findViewById(R.id.linearLayout);
for(int i=0;i<5;i++){
View to_add = inflater.inflate(R.layout.layout_grid_01,options_layout,false);
TextView text = (TextView) to_add.findViewById(R.id.txtView1);
text.setText("Print - " + i);
for(int j=0;j<5;j++){
final View add=inflater.inflate(R.layout.layout_grid_02, (ViewGroup) to_add,false);
TextView text1 = (TextView) add.findViewById(R.id.txtView2);
text1.setText("Print double - " + j);
add.setOnTouchListener(new OnSwipeTouchListener(MainActivity.this){
public void onSwipeLeft() {
}
public void onSwipeTop() {
}
public void onSwipeBottom() {
}
@Override
public void onSwipeRight() {
overridePendingTransition(R.anim.animation,R.anim.animation_2);
}
});
((ViewGroup) to_add).addView(add);
}
options_layout.addView(to_add);
}
animation.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="-100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="0%"
android:toXDelta="100%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="700" />
</set>
动画_2.xaml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="-100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700"/>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="0%"
android:toXDelta="100%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="700" />
</set>
这就是我在上面尝试过的代码。
你有什么想法吗
谢谢。如果您想使用动画,可以使用称为viewFlipper的东西
这里有一个不错的教程:在您的
res/anim
文件夹中添加以下文件:
_left.xml中的幻灯片\u:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true">
<translate android:fromXDelta="-100%"
android:toXDelta="0%" android:fromYDelta="0%"
android:toYDelta="0%" android:duration="300">
</translate>
</set>
你用过可视寻呼机吗?没有。我想用上面的方法做这件事。谢谢朋友。我要试穿一下。
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="-50%p"
android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="@android:integer/config_mediumAnimTime" />
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate android:fromXDelta="0%" android:toXDelta="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="0">
</translate>
</set>
overridePendingTransition(R.anim.slide_in_left,R.anim.slide_out_right);