2012-08-05 42 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" 

它适用于我很好,即使对于小屏幕布局也没有产生任何问题

相关问题