簡體   English   中英

在Android中定位重疊視圖

[英]Positioning overlapped view in Android

簡單-無論屏幕分辨率和密度如何,如何將一個視圖放置在嚴格定義的位置的另一個視圖(可能會縮小)的頂部?

示例-將TextView始終放在金字塔的圖像頂部。 當我在dp單位上使用頁邊距(“框架”或“相對”布局)時,它們在不同的屏幕尺寸上會失敗:(

交代

XML

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM