[英]Make ImageView to look the same on different devices
我有一個帶有ImageView的RelativeLayout,它具有以下屬性,
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="100dp"
android:layout_marginLeft="100dp"
android:layout_marginTop="100dp"
android:layout_marginBottom="300dp"
因此,顯然100dp在不同的設備上看起來並不一樣。 如何使ImageView在平板電腦上的外觀與在手機上的外觀相同? 僅使用一種布局
您可以使用ConstraintLayout
的layout_constraintGuide_percent
屬性,以便尺寸始終與屏幕的寬度和高度有關。
請參閱(不建議使用的) PercentRelativeLayout
文檔中的示例,以了解如何使用ConstraintLayout
實現目標。
問題是您已將ImageView
定義為屏幕尺寸減去某些邊距。 因此,在小屏幕上它將非常小,在大屏幕上它將非常大。
您最好簡單地定義您希望它直接多大。 您的“電話”屏幕截圖看起來可能是在使用320dp寬屏,因此您可以這樣編寫:
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"/>
現在,您的圖像視圖在每個屏幕上將始終為〜2.5cm寬/高,水平居中,並且距屏幕頂部邊緣約2cm。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.