私の知る限り、これの間には相対的なつながりがあります。
つまり、非表示のテキストビューを画面の右側から画面の左側に変換する場合、ボタンをクリックすると、実際には X 方向 (画面の右側) の 100% から X の 0%に変換する必要があります。・方向(画面左側)。
この時点では、Y 方向をまったく変更する必要はありません。したがって、両方のオプションで 0% になります。最終的には、次のようになります。
fromXDelta 100%
toXDelta 0%
fromYDelta 0%
toYDelta 0%
要件に応じて、このパーセンテージを 0 から 100 の間で設定することにより、コンポーネントの表示を制限できます。
同様に、コンポーネントを Y 方向にも変換する必要がある場合は、0% を他の値に変更する必要があります。
願っています、今あなたには明らかです。
編集 :
あなたの要件では、ボタン1のonclickをオーバーライドする必要があり、そこでボタン2の可視性と翻訳を制御できます。
res の anim フォルダーにアニメーション ファイルを作成します。
translate_button.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);
}
}
});
...