我有一个活动,有RecyclerView(可选在a CardView)和aFloatingActionButton
我希望FAB始终位于右下方的屏幕上,但是当我滚动到结尾时RecyclerView,FAB隐藏了最后一项的部分内容.
使用android:layout_marginBottom="48dp"父CardView(或RecyclerView拆卸后本身CardView)修复的问题,但它会导致RecyclerView收缩到屏幕大小减去48dp保证金.
我希望它RecyclerView是全尺寸(即适合所有项目),但当我滚动项目直到我到达最后一项时,应该有该边距,以便FAB不覆盖最后一项RecyclerView.这类似于Google Inbox/Gmail应用中电子邮件列表的行为.
我已经看到许多类似(但不相同)问题的问题,但没有一个解决方案适合我.我知道这个问题应该有一些简单的解决方法,而且我不想扩展LinearLayoutManager,因为这个问题似乎太多了.我也不想在滚动时隐藏FAB.
这是我到目前为止:
activity_main.xml中
<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:background="@color/colorBackground"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/card_list"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:onClick="onClick"
app:srcCompat="@drawable/ic_add"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
card_list.xml
<android.support.v7.widget.CardView
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:layout_marginTop="@dimen/activity_vertical_margin"
android:background="@android:color/white"
android:layout_marginBottom="48dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main">
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/> …Run Code Online (Sandbox Code Playgroud) android android-layout android-cardview floating-action-button android-recyclerview
我开始使用MPAndroidChart库来构建一个StackedBarChart显示三个y值.这是代码:
public class Plot
{
final Context context;
final BarData data;
private int count;
public StackedBarPlot(Context context)
{
this.context = context;
data = setData();
}
protected BarData setData()
{
final List<BarEntry> entries = new ArrayList<>();
for (DatabaseEntry entry : entryList)
{
final float total = (float) entry.getTotal();
final float[] y = {100 * entry.getN1() / total,
100 * entry.getN2() / total, 100 * entry.getN3() / total};
entries.add(new BarEntry(/*long*/entry.getDate(), y));
}
count = entries.size();
final BarDataSet dataset …Run Code Online (Sandbox Code Playgroud) android ×2