2016-05-09 9 views
1

Ich habe einen Frieden des Codes geschrieben, die Animation durchführen. für, dass ich eine Animationsdatei in anim Ordner geschrieben habenWie übersetzt man mit glatter Animation in Android

my animone.xml file 
<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:interpolator="@android:anim/linear_interpolator" 
    android:fillAfter="true"> 
    <translate 
     android:fromYDelta="0%p" 
     android:toYDelta="-5%p" 
     android:duration="1500"/></set> 

und hier wende ich die Animation auf der Ansicht, dass ein Linearlayout

Animation animate= AnimationUtils.loadAnimation(context,R.anim.animone); 
      subProfile.setVisibility(View.VISIBLE);//subProfile is a linear layout 
      subProfile.startAnimation(animate); 

so, wenn ich diesen Code ausführen. Es ändert sich plötzlich die Position der Ansicht, ohne dass das Gleiten nach der angegebenen Dauer erfolgt. ich möchte es glatt machen. bitte hilfe.

---------------- hier ist meine komplette Code ---------------- Haupt Fragment Datei

<FrameLayout 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="com.example.videosapp.Fragments.HomeFragment" 
android:background="@drawable/background"> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <LinearLayout 
      android:id="@+id/my_pofile" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:layout_centerInParent="true" android:visibility="gone"> 

      <ImageView 
       android:id="@+id/dshImg" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:layout_centerHorizontal="true" 
       android:background="@drawable/dashboard"/> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Dashboard" 
       android:layout_below="@id/dshImg" 
       android:textColor="@color/colorText" 
       android:textSize="18sp" 
       android:layout_gravity="center_horizontal" /> 
     </LinearLayout> 
     <LinearLayout android:id="@+id/podcast" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:layout_centerInParent="true" android:visibility="gone"> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/podcast"/> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Podcast" 
       android:textColor="@color/colorText" 
       android:textSize="18sp" /> 
     </LinearLayout> 
     <LinearLayout android:id="@+id/photo_gallery" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:layout_centerInParent="true" android:visibility="gone"> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/photo_gallery"/> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Photo Gallery" 
       android:textColor="@color/colorText" 
       android:textSize="18sp" /> 
     </LinearLayout> 
     <LinearLayout android:id="@+id/social" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:layout_centerInParent="true" android:visibility="gone"> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/social"/> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Social" 
       android:textColor="@color/colorText" 
       android:textSize="18sp" /> 
     </LinearLayout> 
     <LinearLayout android:id="@+id/about_us" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:layout_centerInParent="true" android:visibility="gone"> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/aboutus"/> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Know US" 
       android:textColor="@color/colorText" 
       android:textSize="18sp" /> 
     </LinearLayout> 
     <LinearLayout android:id="@+id/contact_us" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:layout_centerInParent="true" android:visibility="gone"> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/contact_us"/> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Contact Us" 
       android:textColor="@color/colorText" 
       android:textSize="18sp" /> 
     </LinearLayout> 
     <LinearLayout android:id="@+id/setting" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:layout_centerInParent="true" android:visibility="gone"> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/settings"/> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Settings" 
       android:textColor="@color/colorText" 
       android:textSize="18sp" 
       android:layout_gravity="center_horizontal" /> 
     </LinearLayout> 
     <LinearLayout android:id="@+id/exit_layout" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:layout_centerInParent="true" android:visibility="gone"> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/exit"/> 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Exit" 
       android:textColor="@color/colorText" 
       android:textSize="18sp" /> 
     </LinearLayout> 
     <ImageView 
      android:id="@+id/menu_home" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/center_menu" 
      android:layout_centerInParent="true" /> 
    </RelativeLayout> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <!--On following LinearLayout i want to apply animation--> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_centerInParent="true" 
     android:id="@+id/profile" 
     android:visibility="gone" 
     > 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/my_profile_icon"/> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:text="My Profile" 
      android:gravity="center_vertical" 
      android:textColor="@color/colorText" 
      android:textSize="20sp" 
      /> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="15dp" 
     android:orientation="horizontal" 
     android:layout_centerInParent="true" 
     android:id="@+id/programs" 
     android:visibility="gone" 
     > 
     <ImageView 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:src="@drawable/folder_icon"/> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:text="My Programs" 
      android:gravity="center_vertical" 
      android:textColor="@color/colorText" 
      android:textSize="20sp" 
      /> 
    </LinearLayout> 
</RelativeLayout> 

---------------------- Animation XML-Datei ------------------- ---

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 

<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="300" 
    android:fromYDelta="0%" 
    android:interpolator="@android:anim/decelerate_interpolator" 
    android:toYDelta="-100%" /></set> 

----------- Java-Datei, in dem ich die Animation auf Click-Ereignis gelten ---------

public void onClick(View v) { 
    switch (v.getId()) { 
     case R.id.my_pofile: 
      animate= AnimationUtils.loadAnimation(ctx,R.anim.animone); 
      subProfile.setVisibility(View.VISIBLE); 
      subProfile.startAnimation(animate); 
    break; 
    //other cases 
}} 
+0

Unterschied zwischen YDelta ist sehr weniger. Versuchen Sie, die Dauer zu erhöhen –

+0

Ich habe bereits versucht, aber es hat keine Änderungen. –

+0

Interpolator aus Satz entfernen und Maßstabsregister hinzufügen. Beispiel: –

Antwort

1

Versuchen Sie folgendes:

<?xml version="1.0" encoding="utf-8"?> 

<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="300" 
    android:fromYDelta="0%" 
    android:interpolator="@android:anim/decelerate_interpolator" 
    android:toYDelta="-100%" /> 
+0

es ist immer noch nur den Standort wechseln ohne Animation fühlen –

+0

@SharadGautam können Sie bitte den vollen Code veröffentlichen? – Sabari

+0

ja .now bitte überprüfen, dass ich meine Frage bearbeitet habe. –

Verwandte Themen