在使用动画

时间:2016-03-26 18:33:40

标签: c# android android-layout animation xamarin

我试图在展开一个布局/视图时隐藏所有其他布局/视图。 这工作正常,但我想要实现使用动画来丰富用户体验。我怎么能实现这一点我对xamarin android非常新。感谢非常感谢。

main.axml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:id="@+id/help_title_gest"
        android:text="Header_label 1"
        android:clickable="true"
        android:background="#ff3333"
        android:onClick="toggle_contents" />
<!--content to hide/show -->
    <TextView
        android:background="#afafaf"
        android:text="Content 1"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:id="@+id/textView1" />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:id="@+id/help_title_gest2"
        android:text="Header_label 2"
        android:clickable="true"
        android:background="#ff3333"
        android:onClick="toggle_contents" />
<!--content to hide/show -->
    <TextView
        android:background="#afafaf"
        android:text="Content 2"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:id="@+id/textView2" />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:id="@+id/help_title_gest3"
        android:text="Header_label 3"
        android:clickable="true"
        android:background="#ff3333"
        android:onClick="toggle_contents" />
<!--content to hide/show -->
    <TextView
        android:background="#afafaf"
        android:text="Content 3"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:id="@+id/textView3" />
</LinearLayout>

MAinactivity.cs

SetContentView(Resource.Layout.Main);

        // Get our button from the layout resource,
        // and attach an event to it
        textView = FindViewById<TextView>(Resource.Id.help_title_gest);
        contenttextView = FindViewById<TextView>(Resource.Id.textView1);
        contenttextView.Visibility = ViewStates.Gone;


        textView2 = FindViewById<TextView>(Resource.Id.help_title_gest2);
        contenttextView2 = FindViewById<TextView>(Resource.Id.textView2);

        contenttextView2.Visibility = ViewStates.Gone;


        textView3 = FindViewById<TextView>(Resource.Id.help_title_gest3);
        contenttextView3 = FindViewById<TextView>(Resource.Id.textView3);
        contenttextView3.Visibility = ViewStates.Gone;


        textView.Click += (object sender, System.EventArgs e) =>
 {
     if (contenttextView.Visibility == ViewStates.Visible)
     {
         contenttextView2.Visibility = ViewStates.Gone;
         contenttextView.Visibility = ViewStates.Gone;
         contenttextView3.Visibility = ViewStates.Gone;
     }
     else {
         contenttextView2.Visibility = ViewStates.Gone;
         contenttextView3.Visibility = ViewStates.Gone;
         contenttextView.Visibility = ViewStates.Visible;
     }
 };


        textView2.Click += (object sender, System.EventArgs e) =>
        {
            if (contenttextView2.Visibility == ViewStates.Visible)
            {
                contenttextView2.Visibility = ViewStates.Gone;
                contenttextView.Visibility = ViewStates.Gone;
                contenttextView3.Visibility = ViewStates.Gone;
            }
            else {
                contenttextView.Visibility = ViewStates.Gone;
                contenttextView3.Visibility = ViewStates.Gone;
                contenttextView2.Visibility = ViewStates.Visible;
            }
        };


        textView3.Click += (object sender, System.EventArgs e) =>
        {
            if (contenttextView3.Visibility == ViewStates.Visible)
            {
                contenttextView.Visibility = ViewStates.Gone;
                contenttextView2.Visibility = ViewStates.Gone;
                contenttextView3.Visibility = ViewStates.Gone;
            }
            else {
                contenttextView3.Visibility = ViewStates.Visible;
                contenttextView.Visibility = ViewStates.Gone;
                contenttextView2.Visibility = ViewStates.Gone;
            }
        };


    }

0 个答案:

没有答案