3

我正在創建一個簡單的測驗應用程序「目標SDK API 16(4.1果凍豆)」屏幕3.7(480x800 hdpi)。如何自動調整大小,兼容,調整所有Android設備的屏幕大小

這個應用程序在3.7(480x800)上看起來不錯,但是當我在另一個屏幕設備上運行它時,如:2.7(240x320),7.0(1024x600),10.1(1280x800),屏幕分辨率會變差或看起來很糟糕。

更好地瞭解見截圖:

2.7(240×320)

http://postimg.org/image/m3sob88mp/

3.7(480×800)

http://postimg.org/image/wf513w0c1/

7.0(1024×600)

http://postimg.org/image/fc298djn5/

10.1(1280×800)

http://postimg.org/image/isk5gon7p/

我想這兼容/尋找完美與所有的屏幕尺寸就像它會在3.7(480×800 )

如何自動調整大小,兼容,調整所有android設備的屏幕大小,使其看起來十分完美ry屏幕分辨率。

或者我將不得不創建不同的應用或不同的屏幕尺寸。

什麼,我試圖讓屏幕兼容是: 添加這些行 「的AndroidManifest.xml」

<supports-screens> 

     android:resizeable="true" 
     android:smallScreens="true" 
     android:normalScreens="true" 
     android:largeScreens="true" 
     android:xlargeScreens="true" 
     android:anyDensity="true" 

    </supports-screens> 

AndroidManifest.xml中

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.usd.quiztest" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="16" /> 

    <supports-screens> 
     android:resizeable="true" 
     android:smallScreens="true" 
     android:normalScreens="true" 
     android:largeScreens="true" 
     android:xlargeScreens="true" 
     android:anyDensity="true" 
    </supports-screens> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 

     <activity 
      android:name="com.usd.quiztest.Logo" 
      android:label="@string/app_name"    
      android:theme="@android:style/Theme.Black.NoTitleBar" > 

      <intent-filter> 
       <action android:name="android.intent.action.MAIN" />    
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 

     </activity> 

     <activity 
      android:name="com.usd.quiztest.First" 
      android:label="@string/app_name" > 
     </activity>     
     <activity 
      android:name="com.usd.quiztest.Q1" 
      android:label="@string/app_name" > 
     </activity>   
     <activity 
      android:name="com.usd.quiztest.Q2" 
      android:label="@string/app_name" > 
     </activity> 
     <activity 
      android:name="com.usd.quiztest.Q3" 
      android:label="@string/app_name" > 
     </activity> 
     <activity 
      android:name="com.usd.quiztest.Q4" 
      android:label="@string/app_name" > 
     </activity> 
     <activity 
      android:name="com.usd.quiztest.Q5" 
      android:label="@string/app_name" > 
     </activity> 
     <activity 
      android:name="com.usd.quiztest.FinalPage" 
      android:label="@string/app_name" > 
     </activity> 
     <activity 
      android:name="com.usd.quiztest.Score" 
      android:label="@string/app_name" > 
     </activity> 

    </application> 

</manifest> 

first_screen.xml(這是屏幕截圖所示)

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/RelativeLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"  
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="30dp" 
     android:contentDescription="ql" 
     android:gravity="center" 
     android:src="@drawable/ql" /> 

    <Button 
     android:id="@+id/start_button" 
     android:layout_width="254dp" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/imageView1" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="30dp" 
     android:text="Start Quiz Test" 
     android:textColor="#000000" /> 

</RelativeLayout> 
+1

您需要爲所有設備使用不同的drawable。像hdpi,mdpi,xhdpi等。 這將根據設備偏好選擇圖像。 –

+1

供您參考:http://developer.android.com/guide/practices/screens_support.html –

+0

向我們展示您的佈局。 XML,我懷疑有一些錯誤。 – Leandros

回答

7

有一些事情,如果你想支持不同的屏幕尺寸,這是至關重要,:

  • 用途不同可繪爲每個屏幕密度桶(drawables-hdpidrawables-xhdpi等)
  • 使用dp代替px作爲大小的單位。
  • 避免使用絕對大小,使用邊距並讓Android相應地縮放它。

你可以閱讀更多關於支持多種屏幕尺寸here

編輯:

要使用不同的按鈕/字體大小和利潤,你應該使用dimens.xml

res/values-hdpi/dimens.xml 
res/values-xhdpi/dimens.xml 

dimens.xml

+0

好的,我會把圖像放在不同的drawable中,但是按鈕的大小和字體大小,如果我根據屏幕將它們改爲另一個屏幕。如何根據不同的屏幕尺寸自動調整大小。 – Smith

+0

我將不得不增加圖像大小,這取決於不同的drawable。或者我可以在不同的drawable中使用相同的圖像大小。 – Smith

+0

你應該增加它。我建議你閱讀http://developer.android.com/guide/practices/screens_support.html – Leandros

2

使用線性佈局,主佈局,並將其分成部分三,四,五,使用weightSum,高達你你想怎麼劃分,然後使用其他子線性佈局並從總主佈局中爲每個子線性佈局分配weightSum。管理子佈局中的UI小部件。這裏是下面的例子

+0

這不提供問題的答案。一旦你有足夠的[聲譽](http://stackoverflow.com/help/whats-reputation),你將能夠[評論任何職位](http://stackoverflow.com/help/privileges/comment);相反,[提供不需要提問者澄清的答案](http://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-c​​an- I-DO-代替)。 – ddb

相關問題