AFAIK,这之间会有相对的联系。
也就是说,如果您想将隐藏的文本视图从屏幕右侧翻译到屏幕左侧,单击按钮,您实际上需要将其从 X 方向(屏幕右侧)的 100% 翻译为 X 的 0% -方向(屏幕左侧)。
在这一点上,你根本不需要改变 Y 方向。所以这两个选项都是 0%。所以最后,你将拥有:
来自XDelta 100%
toXDelta 0%
来自YDelta 0%
toYDelta 0%
根据您的要求,您可以通过将此百分比设置在 0 到 100 之间来限制组件的视图。
同样,如果您还需要在 Y 方向上平移组件,则需要将 0% 更改为其他值。
希望,你现在清楚了。
编辑 :
根据您的要求,您需要覆盖 button-1 的 onclick,然后您可以控制 button-2 的可见性以及翻译。
在您的 res 的 anim 文件夹中创建动画文件。
翻译按钮.xml:
<?xml version="1.0" encoding="utf-8"?>
<!-- translating button from right to left -->
<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="900"
/>
</set>
现在,在您的活动文件中,
...
// ll is linear layout containing button_2
//counter is used to manage visibility of button_2 on click of button_1,i.e.1st click-button_2 would be visible,on 2nd click on button_1,it would be invisible.
//you can change behavior as per your need
button_2.setVisibility(View.GONE);
button_1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(counter<1)
{
counter++;
button_2.setVisibility(View.VISIBLE);
Animation anim=AnimationUtils.loadAnimation(context, R.anim.translate_button);
button_2.startAnimation(anim);
}
else
{
counter=0;
button_2.setVisibility(View.GONE);
}
}
});
ll.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(counter==1)
{
counter=0;
button_2.setVisibility(View.GONE);
}
}
});
...