您好我在我的Android应用中创建了一个简单的滚动活动。滚动动作具有带有视差效果的CollapsingToolbarLayout和一个锚定到AppbarLayout的浮动动作按钮。
当我向下滚动文本时,工厂消失,当我向上滚动时,再次出现浮动操作按钮。
错误是
1)当floatingActionBar重新出现时,它位于页面的底端,并在一秒之后向上移动到正确的位置(appbarlayout)。 2)在工具栏和页面内容之间有一个奇怪的边缘。
因为看到我想知道这是非常难看的:
1.我怎么解决这个问题? 2.如何保持工厂可见并锚定在折叠工具栏上?
以下是该错误的演示:http://i.giphy.com/LPMqLSl46Yvu0.gif
这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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="toxotes.mystikon.EventActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_event"
android:layout_width="match_parent"
android:layout_height="200dp"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="200dp"
app:layout_collapseMode="parallax"
android:src="@drawable/test"
android:scaleType="centerCrop"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_event"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_event" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_event"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_media_play"
app:layout_anchor="@id/app_bar_event"
app:layout_anchorGravity="bottom|end" />
</android.support.design.widget.CoordinatorLayout>
这是content_event布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView 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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="toxotes.mystikon.EventActivity"
tools:showIn="@layout/activity_event">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:text="@string/large_text" />
</android.support.v4.widget.NestedScrollView>
这是java:
public class EventActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_event);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_event);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab_event);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
}
答案 0 :(得分:0)
就在今天,我遇到了完全相同的问题。您必须将支持库更新到版本24.2.1。在你的构建gradle中。这为我修好了。
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.android.support:support-v13:24.2.1'
compile 'com.android.support:design:24.2.1'
}
但后来我遇到了矢量drawables的问题:
java.lang.IllegalStateException: This app has been built with an incorrect configuration. Please configure your build for VectorDrawableCompat.
以下是遇到相同问题的解决方案:http://android-developers.blogspot.de/2016/02/android-support-library-232.html