2017-02-20 18 views
0

EDIT2анимация заставки экрана панели инструментов изменения размера

Все работает теперь, плавающий OnClick слушатель действия кнопки не работает, за исключением.


EDIT

Ok так я пришел с полу-решения я удалил AppBarLayout из activity_main.xml, и теперь он не мерцает больше. Единственное, что панель действий полностью белая и не сливается с цветом панели инструментов. Как я могу это исправить?


Я следовал this сайт для того, чтобы достичь этой анимации (без вида ресайклера хотя):

image

Единственное, что мое мерцает много, и я не знать, где может быть проблема. Также панель инструментов становится меньше, чем размер по умолчанию. Спасибо

MainActivity.java

public class MainActivity extends AppCompatActivity { 
private final String PREFS_NAME = "MyPrefsFile"; 
private boolean doubleBackToExitPressedOnce = false; 
private CoordinatorLayout main_content; 
private FloatingActionButton fab; 
private int mContentViewHeight; 
private Toolbar mToolbar; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    this.setTitle(getString(R.string.title_main_activity)); 
    main_content = (CoordinatorLayout) findViewById(R.id.main_content); 

    fab = (FloatingActionButton) findViewById(R.id.fab);/* 
    fab.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      startActivity(new Intent(MainActivity.this, BasicActivity.class)); 
     } 
    });*/ 
    // Fake a long startup time 
    new Handler().postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      onFakeCreate(); 
     } 

    }, 100); 
} 

    private void onFakeCreate() { 
     setContentView(R.layout.activity_onboarding_placeholder); 

     TextView titleTextView = (TextView) findViewById(R.id.text_title); 
     ViewCompat.animate(titleTextView).alpha(1).start(); 

     mToolbar = (Toolbar) findViewById(R.id.toolbar); 
     mToolbar.getViewTreeObserver().addOnPreDrawListener(
       new ViewTreeObserver.OnPreDrawListener() { 
        @Override 
        public boolean onPreDraw() { 
         mToolbar.getViewTreeObserver().removeOnPreDrawListener(this); 
         final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); 
         final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); 

         mToolbar.measure(widthSpec, heightSpec); 
         mContentViewHeight = mToolbar.getHeight(); 
         collapseToolbar(); 
         return true; 
        } 
       }); 
    } 

    private void collapseToolbar() { 
     int toolBarHeight; 
     TypedValue tv = new TypedValue(); 
     getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true); 
     toolBarHeight = TypedValue.complexToDimensionPixelSize(
       tv.data, getResources().getDisplayMetrics()); 

     ValueAnimator valueHeightAnimator = ValueAnimator 
       .ofInt(mContentViewHeight, toolBarHeight); 

     valueHeightAnimator.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() { 

        @Override 
        public void onAnimationUpdate(ValueAnimator animation) { 
         ViewGroup.LayoutParams lp = mToolbar.getLayoutParams(); 
         lp.height = (Integer) animation.getAnimatedValue(); 
         mToolbar.setLayoutParams(lp); 
        } 
       }); 

     valueHeightAnimator.start(); 
     valueHeightAnimator.addListener(
       new AnimatorListenerAdapter() { 

        @Override 
        public void onAnimationEnd(Animator animation) { 
         super.onAnimationEnd(animation); 

         // Animate fab 
         ViewCompat.animate(fab).setStartDelay(600) 
           .setDuration(400).scaleY(1).scaleX(1).start(); 

        } 
       }); 
    } 
[...] 

Splash_background.xml

<?xml version="1.0" encoding="utf-8"?> 
<layer-list 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:opacity="opaque" 
    > 
    <item> 
     <shape> 
      <solid android:color="@color/background"/> 
     </shape> 
    </item> 

    <item 
     android:height="180dp" 
     android:gravity="top"> 
     <shape android:shape="rectangle"> 
      <solid android:color="?colorPrimary"/> 
     </shape> 
    </item> 
</layer-list> 

activity_main.xml (обновлено)

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    android:id="@+id/main_content" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context=""> 

     <android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="156dp" 
    android:background="?colorPrimary" 
    android:elevation="4dp" 
    app:theme="@style/ThemeOverlay.AppCompat.Light"/> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@drawable/ic_add_white_24dp" 
     app:fabSize="normal"/> 

</android.support.design.widget.CoordinatorLayout> 

Android mainifest.xml

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

    <application 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme"> 
     <activity 
      android:name=".MainActivity" 
      android:theme="@style/AppTheme.NoActionBar" /> 
     <activity 
      android:name=".SplashActivity" 
      android:theme="@style/SplashTheme"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name=".BasicActivity" 
      android:label="@string/title_activity_basic" 
      android:parentActivityName=".MainActivity"> 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value="" /> 
     </activity> 
     <activity 
      android:name=".ExtraActivity" 
      android:label="@string/title_activity_extra" 
      android:parentActivityName=".BasicActivity"> 
      <meta-data 
       android:name="android.support.PARENT_ACTIVITY" 
       android:value="" /> 
     </activity> 
    </application> 

</manifest> 
+0

его работа на моем размере боковой панели инструментов тоже нормальна –

ответ

0

Пожалуйста, проверьте стиль в вашем project.toolbar анимации работает отлично на моей стороне.

<resources> 
    <style name="Button" parent="Theme.AppCompat"> 
     <item name="colorControlHighlight">@color/indigo_500</item> 
     <item name="colorButtonNormal">@color/pink_200</item> 
    </style> 
</resources> 

также проверить Билд Gradle

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.2" 

    defaultConfig { 
     applicationId "" 
     minSdkVersion 21 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:23.1.1' 
    compile 'com.android.support:cardview-v7:23.1.1' 
    compile 'com.android.support:recyclerview-v7:23.1.1' 
    compile 'com.android.support:design:23.1.1' 
} 

Надеется, что это помогает. :)

+0

Спасибо. Прежде чем вы прокомментировали, у меня закончилось терпение и все удалили, но вы дали мне волю, чтобы попробовать еще раз. Я сделал это снова с нуля самым чистым возможным способом, и он действительно работает сейчас. Я думаю, это потому, что я не создал и не установил «AppTheme.Placeholder». Теперь единственное, что теперь делает onclicklistener fab больше не работает. также кнопки меню на панели действий исчезли. Не могли бы вы помочь мне? спасибо *** edit *** ok Я исправил проблему с меню, используя setSupportActionBar (панель инструментов); fab onclicklistener проблема все еще существует tho – oxcened

+0

одна проблема с этим. После того, как арендатор в приложении не работает. :) –

+0

fab накладывается на другие виды i.e onFakeCreate() fuction –