2012-08-05 43 views
0

我在Android中遇到了XML問題。在圖形佈局視圖中,它看起來完全是我想要的,但是當我在10.1英寸的屏幕上運行模擬時,它與父寬度相匹配但不是高度。當我在10.1英寸平板電腦上運行模擬時,寬度或高度。這是我的代碼,Android relativeLayout在模擬中不匹配父級,但是在圖形視圖中

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" android:background="#fff"> 

     <!-- Header Starts--> 
     <LinearLayout android:id="@+id/header" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="@layout/header_gradient" 
       android:paddingTop="5dip" 
       android:paddingBottom="5dip"> 
       <!-- Logo Start--> 
       <ImageView android:src="@drawable/logo" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginLeft="10dip"/> 
       <!-- Logo Ends --> 
     </LinearLayout> 
     <!-- Header Ends --> 
     <!-- Footer Start --> 
     <LinearLayout android:id="@+id/footer" 
       android:layout_width="match_parent" 
       android:layout_height="90dip" 
       android:background="@layout/footer_repeat" 
       android:layout_alignParentBottom="true"> 
     </LinearLayout> 
     <!-- Footer Ends --> 

     <!-- Registration Form --> 
     <LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:padding="10dip" 
      android:layout_below="@id/header"> 
      <!-- Full Name Label --> 
      <TextView android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textColor="#372c24" 
       android:text="Full Name"/> 
      <EditText android:id="@+id/reg_fullname" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="5dip" 
       android:singleLine="true" 
       android:layout_marginBottom="20dip"/> 
      <!-- Email Label --> 
      <TextView android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textColor="#372c24" 
       android:text="Email"/> 
      <EditText android:id="@+id/reg_email" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="5dip" 
       android:singleLine="true" 
       android:layout_marginBottom="20dip"/> 
      <!-- Password Label --> 
      <TextView android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:textColor="#372c24" 
       android:text="Password"/> 
      <EditText android:id="@+id/reg_password" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:password="true" 
       android:singleLine="true" 
       android:layout_marginTop="5dip"/> 
      <!-- Register Button -->  
      <Button android:id="@+id/btnRegister" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="10dip" 
       android:text="Register New Account"/> 
      <!-- Link to Login Screen --> 
      <TextView android:id="@+id/link_to_login" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="40dip" 
       android:layout_marginBottom="40dip" 
       android:text="Have an account? Login here" 
       android:gravity="center" 
       android:textSize="20dip" 
       android:textColor="#025f7c"/> 

     </LinearLayout> 
     <!-- Registration Form Ends --> 


    </RelativeLayout> 
</ScrollView> 

這是它是如何在圖形佈局所示,是我多麼希望它看起來,

enter image description here

這是它的外觀在Android的虛擬機3.2模擬,

enter image description here

最後,這是它的外觀在我的三星Galaxy 10.1" 平板電腦,

enter image description here

任何人都可以看到我在哪裏呢?謝謝

+0

嘗試:在你的'manifest'中使用'android:targetSdkVersion =「11」' – 2012-08-05 16:26:39

回答

1

只需添加 android:largeScreens="true"android:xlargeScreens="true"

0

看起來像活動調用錯誤的佈局.xml!

檢查您的登錄活動是否設置了正確的視圖。

setContentView(R.layout.thelayoutyouareusing); 

此外,您可能將錯誤的活動設置爲應用程序啓動時啓動的登錄(第一個)活動。你檢查你的清單文件:

<activity android:name=".YourFirstActivity" 
       android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

的第一項活動是一個與代碼的意圖器部分

+0

這可能是問題所在。目前,一旦應用程序啓動,我就有一個IF聲明。如果存在cookie,則用戶登錄並顯示main.xml,否則,我會顯示login.xml,如下所示: if(loggedin())setContentView(R.layout.main); } // else username has been been stored,prompt login else { \t setContentView(R.layout.login); } 是這個問題嗎? – rusty009 2012-08-05 16:29:49

+0

是main.xml中看起來像第二張和第三張圖片的那個?如果是,那麼是的,你打電話的觀點有問題 – bernlim 2012-08-05 16:34:33

0

實在不行再放棄minWidth屬性,具有較大值到最上面的父級佈局標記,如

android:minWidth="1400dp" 

它適用於我很好,即使對於小屏幕布局也沒有產生任何問題

相關問題