1

私はアニメーションが初めてです。ボタンにスピンアニメーションがあります。問題は、そのボタンのアニメーションが実行されると、ボタンがレイアウト内の他のボタンと交差することです。そのため、アニメーション中、移動中のボタンは他のボタンに覆われているため見えません。アニメーションをレイアウトの最上層にとどめる方法について何か考えはありますか? API 8 と互換性のあるソリューションを見つけたいと思います。

//create shake animation
    final Animation shakeIt = AnimationUtils.loadAnimation(this, R.anim.shake);
    findViewById(R.id.button_spin).startAnimation(shakeIt);


// use shake animation
    spinnerButton.startAnimation(shakeIt);

編集:(ここにもっと多くの情報があります)

それで、私は過去数時間それをいじって、さらにいくつかのことを発見しました。Lecho の直感は正しいです。z オーダーは、ウィジェットが別のウィジェットの「上」または「下」に移動するかどうかを左右する要因です。私が直面している問題は、次の 2 つのことが原因である可能性があります。

  1. ビュー ビューの前面にあるボタン (および元に戻したい) には、アクティビティの終了近くで編集されたテキストがあります。ウィジェットに再描画を強制するテキストを追加すると、そのビューの Z オーダーが変更されますか?

  2. ボタンのテキストは onResume() で変更され、そのメソッドでボタンの Z オーダーを変更できないようです???

上記の2つの質問への回答は私の問題を解決します

編集 2: 問題の XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bg"
    android:orientation="vertical"
     >

     <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="0dp"
       android:orientation="vertical"
       android:layout_weight=".7"
       android:layout_marginTop="5dp" >

         <Button
            android:id="@+id/categoryButton"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@drawable/drop"
            android:prompt="@string/planet_prompt"
            android:paddingRight="20dp"
            android:textColor="#000000"
            android:textStyle="bold"
            android:textSize="35dp"
            />


     </LinearLayout>


 <LinearLayout
     android:layout_width="match_parent"
     android:layout_height="0dp"
     android:layout_weight="0.1"
     android:orientation="horizontal" >

     </LinearLayout>

   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="0dp"
       android:orientation="horizontal"
       android:layout_weight="1.5" >

               <LinearLayout
               android:layout_width="0dp"
               android:layout_height="match_parent"
               android:orientation="horizontal"
               android:layout_weight="1" >
               </LinearLayout>

                <Button
                android:id="@+id/button_spin"
                android:layout_width="0dp"
                android:layout_weight="2.35"
                android:layout_height="fill_parent"
                android:background="@drawable/letseat"
                android:layout_gravity="center_horizontal"
                android:gravity="center" />

              <LinearLayout
               android:layout_width="0dp"
               android:layout_height="match_parent"
               android:orientation="horizontal"
               android:layout_weight="1" >
               </LinearLayout>

</LinearLayout>



 <LinearLayout
     android:layout_width="match_parent"
     android:layout_height="0dp"
     android:layout_weight="3"
     android:orientation="vertical">

      <Button
        android:id="@+id/button_additems"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:background="@drawable/add_rest"
        android:gravity="center_horizontal" />   

        <Button
        android:id="@+id/button_showrestaurant"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:background="@drawable/edit_rest"
        android:gravity="center_horizontal" />

        <Button
        android:id="@+id/button_nearbyplaces"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:background="@drawable/whats_near"
        android:gravity="center_horizontal" />

  </LinearLayout>
</LinearLayout>
4

1 に答える 1

0

ただの私の考えです。Android では、ビューが XML に追加される順序によって z オーダーが決定されます。おそらく、アニメーション化されたボタンが他のボタンよりも前にxmlに追加されたため、「より深く」なっています。アニメーション化されたボタンを後で XML に配置するか、レイアウトでメソッドbringChildToFront(buttonView)を使用するか、コードからボタンをレイアウトに追加してください。

編集:

広告 1. テキストを追加しても Z オーダーは変わらないようです。テキストを変更button.bringToFront()してZオーダーを呼び出すと変更されますが、呼び出しbringToFront()たりsetText()単独で呼び出したりすると変更されません。

広告 2.onResumeテキストを追加しても Z オーダーは変更されませんが、メソッドbringToFront()は期待どおりに機能するようです。

現在、これらのメソッドをビュー アニメーションと一緒にテストすることはできません。

テスト活動:

public class MainActivity extends Activity {
    private int i = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final Button btn1 = (Button) findViewById(R.id.btn1);
        final Button btn2 = (Button) findViewById(R.id.btn2);
        btn2.bringToFront();
        final Button btn3 = (Button) findViewById(R.id.btn3);
        btn3.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if ((i % 2) == 0) {
                    final Button btn1 = (Button) findViewById(R.id.btn1);
                    btn1.setText("BUTTON_BLACK_NEW");
                    btn1.bringToFront();
                } else {
                    final Button btn2 = (Button) findViewById(R.id.btn2);
                    btn2.setText("BUTTON_GREY_NEW");
                    btn2.bringToFront();
                }
                ++i;

            }
        });

    }

    @Override
    protected void onResume() {
        super.onResume();
        if ((i % 2) == 0) {
            final Button btn1 = (Button) findViewById(R.id.btn1);
            btn1.bringToFront();
        } else {
            final Button btn2 = (Button) findViewById(R.id.btn2);
            btn2.bringToFront();
        }
        ++i;
    }

}

レイアウト:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" 
android:id="@+id/main_layout">

<Button
    android:id="@+id/btn1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/black"
    android:text="BUTTON_BLACK"
    android:textColor="@android:color/white" />

    <Button
        android:id="@+id/btn2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/darker_gray"
        android:text="BUTTON_GREY"
        android:textColor="@android:color/black" />

    <Button
        android:id="@+id/btn3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CHANGE_Z"
        android:layout_below="@+id/btn2" />

</RelativeLayout>
于 2012-12-04T19:32:48.293 に答える