在android中创建关于cardview的视图

前端之家收集整理的这篇文章主要介绍了在android中创建关于cardview的视图前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想创建这个布局

这是我使用此代码的cardview(灰色视图)和imageview(蓝色视图)

  1. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:app="http://schemas.android.com/apk/res-auto"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:background="@color/abc_search_url_text_normal"
  6. android:orientation="vertical">
  7.  
  8. <android.support.v7.widget.CardView
  9. android:layout_width="match_parent"
  10. android:layout_height="100dp"
  11. android:layout_alignParentBottom="true"
  12. android:layout_gravity="bottom"
  13. android:layout_marginBottom="3dp"
  14. android:paddingTop="5dp"
  15. app:cardBackgroundColor="@color/abc_input_method_navigation_guard">
  16.  
  17.  
  18. </android.support.v7.widget.CardView>
  19.  
  20. <ImageView
  21. android:layout_width="100dp"
  22. android:layout_height="100dp"
  23. android:layout_gravity="bottom"
  24. android:layout_marginBottom="30dp"
  25. android:layout_marginRight="10dp"
  26. android:scaleType="fitXY"
  27. android:src="@drawable/abc_ratingbar_full_material" />
  28.  
  29. </FrameLayout>

但在结果我的图像视图回到cardview我尝试reletivelayout而不是framelayout但相同的结果.

解决方法

尝试:

>使用RelativeLayout
>将ImageView与父右/末端对齐,并添加右/尾边距
>将FAB对齐到卡片视图的顶部并添加负边距

  1. <RelativeLayout
  2. ...>
  3. <CardView
  4. android:id="@+id/cardView"
  5. android:layout_width="match_parent"
  6. android:layout_height="120dp"
  7. />
  8.  
  9. <ImageView
  10. android:id="@+id/fab"
  11. android:layout_width="wrap_content"
  12. android:layout_height="wrap_content"
  13. android:layout_alignParentRight="true"
  14. android:layout_alignTop="@id/cardView"
  15. android:layout_marginTop="-32dp"
  16. android:layout_marginRight="20dp"
  17. />
  18.  
  19. </RelativeLayout>

猜你在找的Android相关文章