2012-11-26 119 views
0

我正在Eclipse上的4in模擬器上開發我的應用程序。我的手機是4.6英寸的Android設備,當我在那裏測試時,內容無法正確縮放。Android沒有調整大小?

它看起來像手機保持在相同的大小的內容,它只是將所有東西都上移,並留出額外的空間。

從我讀過的內容來看,我認爲它應該保持相同的佈局,只要我使用dp而不是。這是否意味着我的圖像也需要dp?

有什麼建議嗎?

編輯:

下面是一些代碼:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/tfltestbg2" 
    android:orientation="vertical" > 

    <ImageView 
      android:layout_width="fill_parent" 
      android:layout_height="55dp" 
      android:background="@drawable/tfl_header_port" 
      android:gravity = "center_horizontal" 
      android:layout_gravity = "center_horizontal"/> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="40dp" 
     android:orientation="horizontal" 
     android:layout_gravity = "center" 
     android:gravity = "center" 
> 

     <Button 
      android:id="@+id/buttonTakePic" 
      android:layout_width="100dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="left" 
      android:gravity = "left" 
      android:background="@drawable/takepic_button" /> 

     <Button 
      android:id="@+id/mMegaGalleryButton" 
      android:layout_width="120dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="center" 
      android:gravity = "center" 
      android:background="@drawable/add_fotos" /> 

     <Button 
      android:id="@+id/mGalleryButton" 
      android:layout_width="100dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="right" 
      android:gravity = "right" 
      android:background="@drawable/selectpic" 
      android:paddingLeft = "10dp" 
      android:paddingRight = "10dp"/> 


    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/image_container" 
     android:layout_width="match_parent" 
     android:layout_height="300dp" 
     android:layout_gravity="center" 
     android:background="@drawable/outline_box" 
     android:gravity="center"> 

     <FrameLayout 
      android:layout_width = "match_parent" 
      android:layout_height = "fill_parent" 
      android:gravity = "center" 
      android:layout_gravity = "center"> 

      <ImageView 
       android:id="@+id/image" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_gravity="center" 
       android:background = "@drawable/blank" 
       android:gravity="center" /> 

      <ImageView 
       android:id="@+id/picsImage" 
       android:layout_width = "100dp" 
       android:layout_height = "100dp" 
       android:layout_gravity="center" 
       android:gravity="center" 
       android:background = "@drawable/picture_box"/> 
     </FrameLayout> 
    </LinearLayout> 

    <Button 
     android:id="@+id/mEditButton" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:layout_gravity="center" 
     android:background="@drawable/edit_pic_button" /> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="10dp" /> 

    <Button 
     android:id="@+id/buttonUploadPic" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:layout_gravity="center" 
     android:background="@drawable/upload_pic_button" /> 

</LinearLayout> 
+0

發佈一些有問題的XML。 – njzk2

+0

這真的很長,但我會繼續發佈。 – user1513687

+2

不要使用背景進行圖像瀏覽,請使用src。你的3個第一個按鈕有dp-fixed,這意味着它們不會佔用所有空間。爲此使用重量。所有你的一級物品都有固定的高度,這意味着它們不會佔用所有可用的高度。使用重量。 – njzk2

回答

0

使用相對佈局,而不是線性佈局和不使用硬編碼dimesions像40dp,50dp如果不同尺寸屏幕的使用應用程序。

Relative layout

0

問題在你的佈局是,你在錯誤的地方使用固定的值!而不是android:layout_width="100dp"按鈕(這是水平佈局),你應該使用android:layout_width="fill_parent"
您必須爲此按鈕設置layout_weight的非零值,以便它們可以在此佈局中與其他同級兄弟共享空間。到固定DP轉換爲重量

0

最簡單的方法:

變化這樣的:

機器人:layout_width = 「100dp」

這樣:

機器人:layout_width = 「0dp」

android:layout_weight =「100」

do它適用於所有按鈕,並且它們看起來完全像4英寸,並且可以在任何屏幕上完美縮放。