如何在Android中添加一个FloatingActionButton上面的TextView

前端之家收集整理的这篇文章主要介绍了如何在Android中添加一个FloatingActionButton上面的TextView前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在FloatingActionButton上面添加一个TextView,我使用FrameLayout作为TextView和FloatingActionButton的父布局,这里是我的示例代码
  1. <FrameLayout
  2. android:layout_width="wrap_content"
  3. android:layout_height="wrap_content">
  4.  
  5. <android.support.design.widget.FloatingActionButton
  6. xmlns:app="http://schemas.android.com/apk/res-auto"
  7. android:id="@+id/fab"
  8. android:layout_width="wrap_content"
  9. android:layout_height="wrap_content"
  10. app:backgroundTint="#00fff0"
  11. app:borderWidth="0dp"
  12. android:elevation="0dp"
  13. app:fabSize="normal" />
  14.  
  15. <TextView
  16. android:layout_width="wrap_content"
  17. android:layout_height="wrap_content"
  18. android:textColor="#000000"
  19. android:text="above"/>
  20.  
  21. </FrameLayout>

但是没有用,TextView在FloatingActionButton之下,就像这样

我想要这样显示

我很穷,有人可以帮我吗?

解决方法

您只需要将height属性添加到textview
  1. <FrameLayout
  2. android:layout_width="wrap_content"
  3. android:layout_height="wrap_content">
  4.  
  5. <android.support.design.widget.FloatingActionButton
  6. xmlns:app="http://schemas.android.com/apk/res-auto"
  7. android:id="@+id/fab"
  8. android:layout_width="wrap_content"
  9. android:layout_height="wrap_content"
  10. app:backgroundTint="#00fff0"
  11. app:borderWidth="0dp"
  12. android:elevation="0dp"
  13. app:fabSize="normal" />
  14.  
  15. <TextView
  16. android:layout_width="wrap_content"
  17. android:layout_height="wrap_content"
  18. android:textColor="#000000"
  19. android:text="above"
  20. android:elevation="7dp"/>
  21.  
  22. </FrameLayout>

猜你在找的Android相关文章