0

So I implemented the Floating Action Button (FAB) by gabrielemariotti and i don't know if it is just because I am running it in an emulator or what but this is what it ends up looking like:

https://i.stack.imgur.com/cX8uV.jpg

Now I am using an image for the plus but it is one that I made myself. This is the image that I made up:

https://i.stack.imgur.com/CttLY.jpg

^ it is there.....

Also this is my current xml for that layout:

<RelativeLayout 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"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".DataActivity$DataFragment">
<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:foreground="?android:attr/selectableItemBackground"
    android:id="@+id/CardView_1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="5dp"
    android:onClick="CardviewToast"
    card_view:cardCornerRadius="2dp"
    android:elevation="2dp">
    <TextView
        android:text="Current Stats:"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</android.support.v7.widget.CardView>

<ImageButton
    android:id="@+id/fab"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    android:layout_width="@dimen/fab_size"
    android:layout_height="@dimen/fab_size"
    android:layout_gravity="bottom|right"
    android:layout_marginRight="16dp"
    android:layout_marginBottom="16dp"
    android:background="@drawable/ripple"
    android:stateListAnimator="@anim/anim"
    android:src="@drawable/ic_action_add"
    android:elevation="4dp"
    />

EDIT

I think it has to do with :

//Outline
    int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
    Outline outline = new Outline();
    outline.setOval(0, 0, size, size);
    findViewById(R.id.fabdata).setOutline(outline);

I don't have that in my code because

java.lang.RuntimeException: Unable to start activity ComponentInfo{target.totalarchery/target.totalarchery.DataActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOutline(android.graphics.Outline)' on a null object reference

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOutline(android.graphics.Outline)' on a null object reference

Which makes no sense because I have it in the same spot that the example does.

user2999980
  • 31
  • 2
  • 8

2 Answers2

0

Solved it by moving

 //Outline
int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
Outline outline = new Outline();
outline.setOval(0, 0, size, size);
findViewById(R.id.fabdata).setOutline(outline);

into main activity class and not hav it reside in a fragment

user2999980
  • 31
  • 2
  • 8
0

Google now provide floating action button in support library. See my answer to this question Floating Action Button

Community
  • 1
  • 1
Ashish Rawat
  • 5,541
  • 1
  • 20
  • 17