2015-03-02 81 views
0

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

<?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> 

Image to show the layout and image button

相同的图像,如果我在其他一些布局设置的东西做工精细。任何人都可以给我一些指引,看看哪里。 日志中没有错误或警告。 实际png图片如下: plus.png

+0

你想实现浮动按钮? – 2015-03-02 09:47:30

+0

是试验浮动按钮。 – Thebestshoot 2015-03-02 09:51:24

+0

您可以使用框架布局。 – 2015-03-02 10:17:28

回答

0

如果你想实现浮动按钮,更好的方式将使用现有的库:

添加此行对你的build.gradle dependencises:

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> 

,如果你想定制你的FL例如改变颜色浮动按钮,添加此行RelativeLayout属性:

xmlns:fab="http://schemas.android.com/apk/res-auto" 

,并添加下面的属性到AddFloatingActionButton XML

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

我看起来更像是为什么这不是为我工作,而不是只是与一些有用的东西相处。 我实际上并没有在任何应用中实现这种布局,因为我只是在试验,所以想要了解为什么事情不起作用。 – Thebestshoot 2015-03-02 10:00:57

+0

它看起来像加可绘制只是白色的圆圈 - 没有加 – 2015-03-02 10:03:26

+0

无论如何,我听到很多人在stackoverflow和避免使用第三方库的人,作为一个新手,我不知道为什么。你对此有何看法?我只是想知道什么是好的,为什么它是 – Thebestshoot 2015-03-02 10:03:39