[英]Positioning overlapped view in Android
簡單-無論屏幕分辨率和密度如何,如何將一個視圖放置在嚴格定義的位置的另一個視圖(可能會縮小)的頂部?
示例-將TextView始終放在金字塔的圖像頂部。 當我在dp單位上使用頁邊距(“框架”或“相對”布局)時,它們在不同的屏幕尺寸上會失敗:(
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image" />
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginLeft="30dp"
android:layout_gravity="left|bottom" />
</FrameLayout>
When I am using margins (Frame or Relative layout) with dp units they fail on different screen size
是的,由於其他設備的dp不同,它們將始終失敗。
解:
您始終可以使用res
文件夾中的values
文件夾,在其中將值放置到dimens.xml
這樣您的邊距將始終根據所測試的設備而變化。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.