为什么不同的android版本显示不同的GUI?

问题描述:

请看看下面的代码为什么不同的android版本显示不同的GUI?

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/tableLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#FFF" 
    android:gravity="right" 
    android:padding="5dp" 
    android:paddingBottom="5dp" 
    android:stretchColumns="1,2,3" 
    tools:context=".MainActivity" > 

    <TableRow 
     android:id="@+id/tableRow0" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/billTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="right" 
      android:padding="5dp" 
      android:text="@string/billTextView" 
      android:textColor="#000" /> 

     <EditText 
      android:id="@+id/billEditText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_span="3" 
      android:layout_weight="1" 
      android:inputType="numberDecimal" 
      android:longClickable="false" > 

      <requestFocus /> 
     </EditText> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/tenTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_column="1" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="10%" 
      android:textColor="#000" /> 

     <TextView 
      android:id="@+id/fifteenTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="15%" 
      android:textColor="#000" /> 

     <TextView 
      android:id="@+id/twentyTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="20%" 
      android:textColor="#000" /> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/tipTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="right" 
      android:padding="5dp" 
      android:text="@string/tipTxtView" 
      android:textColor="#000" /> 

     <EditText 
      android:id="@+id/tip10EditText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:cursorVisible="false" 
      android:focusable="false" 
      android:gravity="center" 
      android:longClickable="false" 
      android:textSize="14sp" /> 

     <EditText 
      android:id="@+id/tip15EditText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:cursorVisible="false" 
      android:focusable="false" 
      android:gravity="center" 
      android:longClickable="false" 
      android:textSize="14sp" /> 

     <EditText 
      android:id="@+id/tip20EditText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:cursorVisible="false" 
      android:focusable="false" 
      android:gravity="center" 
      android:longClickable="false" 
      android:textSize="14sp" /> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow3" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/totalTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="right" 
      android:padding="5dp" 
      android:text="@string/totalTextView" 
      android:textColor="#000" /> 

     <EditText 
      android:id="@+id/total10EditText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:cursorVisible="false" 
      android:focusable="false" 
      android:gravity="center" 
      android:longClickable="false" 
      android:textSize="14sp" /> 

     <EditText 
      android:id="@+id/total15EditText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:cursorVisible="false" 
      android:focusable="false" 
      android:gravity="center" 
      android:longClickable="false" 
      android:textSize="14sp" /> 

     <EditText 
      android:id="@+id/total20EditText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:cursorVisible="false" 
      android:focusable="false" 
      android:gravity="center" 
      android:longClickable="false" 
      android:textSize="14sp" /> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow4" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/customTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:gravity="right|center_vertical" 
      android:padding="5dp" 
      android:text="@string/customTextView" 
      android:textColor="#000" /> 

     <SeekBar 
      android:id="@+id/customSeekBar" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_span="2" 
      android:layout_weight="1" 
      android:focusable="false" 
      android:paddingLeft="8dp" 
      android:paddingRight="8dp" 
      android:progress="18" /> 

     <TextView 
      android:id="@+id/customTipTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:gravity="center_vertical" 
      android:paddingLeft="5dp" 
      android:text="a" 
      android:textColor="#000" /> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow5" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/tipCustomTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="right" 
      android:padding="5dp" 
      android:text="@string/tipCustomTextView" 
      android:textColor="#000" /> 

     <EditText 
      android:id="@+id/tipCustomEditText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:cursorVisible="false" 
      android:focusable="false" 
      android:gravity="center" 
      android:longClickable="false" 
      android:textSize="14sp" /> 

     <TextView 
      android:id="@+id/totalCustomTextView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center|right" 
      android:padding="5dp" 
      android:text="@string/totalCustomTextView" 
      android:textColor="#000" /> 

     <EditText 
      android:id="@+id/totalCustomEditText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:cursorVisible="false" 
      android:focusable="false" 
      android:gravity="center" 
      android:longClickable="false" 
      android:textSize="14sp" /> 
    </TableRow> 

</TableLayout> 

该项目采用了Android 3.2版本创建的。

这是它是如何被显示的Galaxy Nexus,它被设置为Android版本2.3.3

enter image description here

这是它是如何被显示的Galaxy Nexus,它被设置到Android 3.2版本

enter image description here

正如您所看到的那样,在新版本的GUI中,GUI有点不高兴。看起来组件是重叠的。这就是为什么它不显示组件的边界。请帮忙!

是的,这是正常的。 Android的视觉外观已经被Android 4.0大大抛光。它与你的代码直接无关。 Android会自动执行此操作。

如果您希望所有用户都能看到旧式样,则可以在清单文件的<uses-sdk>标记内设置targetVersion。但是,我劝你不要这样做。

+0

作为另一种选择,您还可以花时间为您的应用程序进行广泛的主题化,如果您愿意付出努力,则可以在所有设备上创建(大部分)一致的体验。 – Blumer 2013-03-07 16:51:39

+0

@Blumer:谢谢你的回复:)。但该应用程序的设计与版本3.2!你的意思是,即使它是使用3.2设计的并在3.2仿真器中测试过的,这是我能得到的吗? – 2013-03-07 17:17:28

+0

@poitroae:好的,你的意思是这是新的风格?当你编写GUI时,这是我们得到的GUI,是这样吗?请帮忙! – 2013-03-07 17:36:47