Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 相对布局中的图像按钮不显示图像_Android_User Interface_Android Relativelayout - Fatal编程技术网

Android 相对布局中的图像按钮不显示图像

Android 相对布局中的图像按钮不显示图像,android,user-interface,android-relativelayout,Android,User Interface,Android Relativelayout,当图像处于相对布局时,我无法看到图像按钮的图像。如果我使用不同的布局,图像工作正常。 我的布局如下: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width=

当图像处于相对布局时,我无法看到图像按钮的图像。如果我使用不同的布局,图像工作正常。 我的布局如下:

<?xml version="1.0" encoding="utf-8"?>
<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">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/cardList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
    <ImageButton
    android:layout_width="56dp"
    android:layout_height="56dp"
    android:src="@drawable/plus"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_marginRight="16dp"
    android:layout_marginBottom="16dp"
    android:id="@+id/fab"
    android:elevation="1dp"
    />

</RelativeLayout>

如果我在其他一些布局中设置相同的图像,效果会很好。谁能给我指点一下该往哪里看。 日志中没有错误或警告。 实际png图像如下所示:

如果要实现浮动按钮,更好的方法是使用现有库:

在build.gradle依赖项上添加此行:

compile 'com.getbase:floatingactionbutton:1.3.0'
并将布局更改为:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            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">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/cardList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

     <com.getbase.floatingactionbutton.AddFloatingActionButton
        android:id="@+id/common_ring_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="10dp"
        android:layout_marginEnd="10dp"
        android:layout_marginRight="10dp"/>

</RelativeLayout>
并将下面的属性添加到
AddFloatingActionButton
xml

fab:fab_colorNormal="@color/floating_button_bg"
fab:fab_colorPressed="@color/floating_button_bg_pressed"

你想实现浮动按钮吗?是的,我正在试验浮动按钮。你可以使用框架布局。@Surender Kumar:你能给我指一些资源吗?请查看这一个框架布局示例-我更想知道为什么这对我不起作用,而不仅仅是处理一些有效的事情。实际上,我并没有在任何应用程序中实现这种布局,正如我所说的,我只是在试验,所以我想知道为什么事情不起作用。看起来plus drawable只是一个白色的圆圈——没有plusAnyway,我从stackoverflow和out的许多人那里听说,他们禁止人们使用第三方库,作为一个新手,我不知道为什么。你觉得怎么样?我只是想知道什么是好的,为什么它是不加是一个png图像,我可以添加到实际问题的图像。我会马上做的,谢谢你让我知道。我在生活中使用了很多开源库,这对我来说总是很好的。如果某个图书馆有很好的意见,使你的工作更容易,你应该使用它
fab:fab_colorNormal="@color/floating_button_bg"
fab:fab_colorPressed="@color/floating_button_bg_pressed"