[英]Layout on Phones vs Tablets on android
我設計了一個圖像視圖為150dp x 150dp的布局。 與手機相比,平板電腦看起來很糟糕。 請參見下圖。
如何使布局看起來也與平板電腦上的手機相似。 使用相同的布局文件,即對於不同的屏幕尺寸不使用不同的布局。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/layout_title"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:background="@drawable/title_with_shadow"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textSize="16sp"
android:text="@string/preview"
android:textColor="@color/title_text_color"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/imgPreviewLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/layout_title"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:background="@drawable/category_item"
android:orientation="vertical">
<ImageView
android:id="@+id/imgPreview"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerHorizontal="true"
android:scaleType="fitXY"
android:src="@drawable/noimage" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/tabcontrolLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/imgPreviewLayout"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:gravity="center_horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:layout_marginLeft="10dp"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="@string/pieces"
android:textColor="#040404"
android:textSize="15sp"
android:textStyle="bold" />
<Spinner
android:id="@+id/spinerCount"
android:layout_width="70dp"
android:layout_height="35dp"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="5dp"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="@string/rotation"
android:textSize="15sp"
android:textStyle="bold" />
<ToggleButton
android:id="@+id/btn_rotate_puzzel"
android:layout_width="wrap_content"
android:layout_height="35dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="5dp"
android:layout_marginRight="10dp"
android:gravity="center_horizontal"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="@string/background"
android:textSize="15sp"
android:textStyle="bold" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/color_selection" />
</LinearLayout>
<ImageButton
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_below="@+id/layout_Rotation"
android:layout_centerHorizontal="true"
android:layout_margin="5dp"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:padding="8dp"/>
</RelativeLayout>
<LinearLayout
android:id="@+id/magic_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@drawable/title_with_shadow"
android:id="@+id/magic_btn"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:textSize="15sp"
android:layout_marginLeft="10dp"
android:text="@string/cheatcode"
android:textColor="@color/title_text_color"
android:textStyle="bold" />
</RelativeLayout>
<include
layout="@layout/panel"
android:background="@drawable/background_with_shadow"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
如何使布局看起來也與平板電腦上的手機相似。 使用相同的布局文件,即對於不同的屏幕尺寸不使用不同的布局。
您不能,必須創建不同的布局。
它不像將設備歸類為電話或平板電腦一樣簡單,甚至不僅僅按照其物理屏幕尺寸進行分類-您可以使兩個設備具有完全相同的物理屏幕尺寸,但具有不同的屏幕分辨率WRT每英寸實際點數和布局看起來會有所不同。
僅在對屏幕尺寸/密度進行細微調整時,與密度無關的像素(dip或dp)的使用才能走得那么遠-僅在差異很小的情況下有效,而在差異較大的情況下則無效。
簡而言之,Android擁有眾多WRT密度(例如ldpi,mdpi,hdpi等)和尺寸(小,中,大等)的原因是,在許多情況下,您不能只創建一個布局並期望它可以在每個設備上進行轉換。
如果您希望應用程序以不同的設備尺寸顯示,則除了布局文件夾外,還必須創建以下文件夾:
布局土地
布局大
布局-土地
布局小
布局小土地
布局-xlarge
布局-x大國
與小屏幕,大屏幕和非常大的屏幕以及水平和垂直模式有關,您必須完成開發,完成后,將Layout文件夾中的所有設計布局復制到這些文件夾...並運行程序...有一些移動或壞處,您可以更改它的屬性並更正...。您必須將此代碼添加到manifest.xml中:
<compatible-screens>
<screen
android:screenDensity="ldpi"
android:screenSize="small" />
<screen
android:screenDensity="mdpi"
android:screenSize="normal" />
<screen
android:screenDensity="xhdpi"
android:screenSize="large" />
<screen
android:screenDensity="xhdpi"
android:screenSize="xlarge" />
</compatible-screens>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.