【问题标题】:Floating Action Button rendering issues浮动操作按钮渲染问题
【发布时间】:2014-10-18 23:22:42
【问题描述】:

所以我实现了 gabrielemariotti 的浮动操作按钮 (FAB),我不知道是因为我在模拟器中运行它还是什么,但它最终看起来像这样:

http://imgur.com/iD1mU7Z

现在我正在使用图片作为加号,但它是我自己制作的。这是我编的图:

http://imgur.com/CqCLAop

^ 它在那里.....

这也是我当前用于该布局的xml

<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"
    />

编辑

我认为这与:

//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);

我的代码中没有这个,因为

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

这没有任何意义,因为我将它放在与示例相同的位置。

【问题讨论】:

    标签: android android-fragments floating-action-button


    【解决方案1】:

    移动解决了

     //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);
    

    进入主要活动类,而不是驻留在片段中

    【讨论】:

      【解决方案2】:

      Google 现在在支持库中提供浮动操作按钮。看我对这个问题的回答 Floating Action Button

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-10-30
        • 1970-01-01
        • 1970-01-01
        • 2020-02-26
        • 1970-01-01
        • 1970-01-01
        • 2015-06-25
        • 1970-01-01
        相关资源
        最近更新 更多