[英]Android RelativeLayout align center of one view on top right corner of another view
[英]Android - How to make one view's center on another view's top right corner inside list item layout
在GridView中,我正在顯示書籍網格。 每本書都有狀態-新書,收藏夾,已完成。 這是示例,我要實現:
我的版式有2個ImageViews:1個用於書籍封面,1個用於書籍狀態圖標(新,完成,收藏)
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/ivCover"
android:layout_width="95dp"
android:layout_height="146dp"
/>
<ImageView
android:layout_width="26dp"
android:layout_height="26dp"
android:src="@drawable/icon_new"
android:layout_alignParentTop="@id/ivCover"
android:layout_alignRight="@id/ivCover"
android:background="@drawable/shape_round_book_status"
android:layout_marginRight="-13dp"
android:layout_marginTop="-13dp"/>
</RelativeLayout>
我發現如何定位一個視圖的另一個視圖的右上角中心在這里 。 在該示例中,解決方案是針對一項-線性布局。 就我而言,我將狀態圖標放在網格視圖項目的一角。 結果,大多數狀態圖標不可見:
如何使一個視圖的中心位於列表項布局內另一視圖的右上角?
為了提高效率,您可以使用比RelativeLayout
更好的性能的FrameLayout
來執行此操作。
假設這樣做的技巧是在書本圖像中留出空白以模擬徽章退出圖像。 像這樣
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/ivCover"
android:layout_width="95dp"
android:layout_height="146dp"
android:layout_marginTop="30dp"
android:layout_marginRight="30dp"
/>
<ImageView
android:layout_width="26dp"
android:layout_height="26dp"
android:src="@drawable/icon_new"
android:layout_gravity="top|right"
android:background="@drawable/shape_round_book_status"/>
</FrameLayout>
調整布局邊距以適合您的設計。
**其他小建議是使用x8大小以“增加材料”(如果需要中等大小,則使用x4)。 而不是95dp使用96,而不是146使用144或152 ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.