为什么我的布局不能扩展到适合其他屏幕?我正在开发nexus 7,布局应该修复以适应整个页面,但事实并非如此。 这是我的布局代码:
<?xml version="1.0" encoding="utf-8"?>
<!--
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout style="@style/TitleBar">
<ImageButton style="@style/TitleBarAction"
android:contentDescription="@string/description_home"
android:src="@drawable/title_home"
android:onClick="onClickHome" />
<ImageView style="@style/TitleBarSeparator"
android:contentDescription="@string/description_title" />
<TextView style="@style/TitleBarText" />
<ImageButton style="@style/TitleBarAction"
android:contentDescription="@string/description_about"
android:src="@drawable/title_about"
android:onClick="onClickAbout" />
<ImageButton style="@style/TitleBarAction"
android:contentDescription="@string/description_connect"
android:src="@drawable/title_connect"
android:onClick="onClickConnect" />
<ImageButton style="@style/TitleBarAction"
android:contentDescription="@string/description_connect"
android:src="@drawable/title_facebook"
android:onClick="onClickFacebook" />
<ImageButton style="@style/TitleBarAction"
android:contentDescription="@string/description_connect"
android:src="@drawable/title_twitter"
android:onClick="onClickTwitter" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Main Title -->
<TextView
android:id="@+id/header1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/heading_1"
android:textSize="20sp"/>
<TextView
android:id="@+id/distance_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/distance"
android:layout_below="@+id/header1"
android:textSize="60sp" />
<TextView
android:id="@+id/header2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/distance_text"
android:layout_marginLeft="210sp"
android:text="@string/heading_2"
android:textSize="20sp" />
<!-- First column -->
<TextView
android:id="@+id/consumption_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="0dp"
android:layout_marginTop="330dp"
android:text="@string/heading_consumption"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/consumption_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/consumption_header"
android:text="@string/text_consumption" />
<TextView
android:id="@+id/avg_consumption_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/heading_avg_consumption"
android:layout_below="@+id/consumption_text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/avg_consumption_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/avg_consumption_header"
android:text="@string/text_avg_consumption" />
<TextView
android:id="@+id/total_consumption_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/heading_total_consumption"
android:layout_below="@+id/avg_consumption_text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/total_consumption_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/total_consumption_header"
android:text="@string/text_total_consumption" />
<!-- Second column -->
<TextView
android:id="@+id/speed_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/heading_speed"
android:layout_marginLeft="100dp"
android:layout_marginTop="150dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/speed_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_speed"
android:layout_marginLeft="100dp"
android:layout_marginTop="170dp" />
<TextView
android:id="@+id/avg_speed_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/heading_avg_speed"
android:layout_marginLeft="100dp"
android:layout_below="@+id/speed_text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/avg_speed_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/text_avg_speed"
android:layout_marginLeft="100dp"
android:layout_below="@+id/avg_speed_header" />
<TextView
android:id="@+id/max_speed_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/heading_maximum_speed"
android:layout_marginLeft="100dp"
android:layout_below="@+id/avg_speed_text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/max_speed_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_below="@+id/max_speed_header"
android:text="@string/text_maximum_speed" />
</RelativeLayout>
</LinearLayout>
清单文件
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="12"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<permission
android:name="com.example.burtoncruiser.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.burtoncruiser.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens= "true"
android:anyDensity="true"
android:compatibleWidthLimitDp="120"/>
<application
android:allowBackup="true"
android:theme="@style/Theme.D1"
android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".CarStatistics"
android:theme="@style/Theme.D1"
android:label="@string/title_feature1"
/>
<activity android:name=".Battery"
android:theme="@style/Theme.D1"
android:label="@string/title_feature2"
/>
<activity android:name=".Map"
android:theme="@style/Theme.D1"
android:label="@string/title_feature3"
/>
<activity android:name=".CarControl"
android:theme="@style/Theme.D1"
android:label="@string/title_feature4"
/>
<activity android:name=".Profile"
android:theme="@style/Theme.D1"
android:label="@string/title_feature5"
/>
<activity android:name=".BluetoothDebugging"
android:theme="@style/Theme.D1"
android:label="@string/title_feature6"
/>
<activity android:name=".AboutActivity"
android:theme="@style/Theme.D1"
android:label="@string/title_about"
/>
<activity android:name=".SearchActivity"
android:theme="@style/Theme.D1"
android:label="@string/title_search"
/>
<activity android:name=".DeviceListActivity"
android:label="@string/select_device"
android:theme="@android:style/Theme.Dialog"
android:configChanges="orientation|keyboardHidden" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyAJstC_UQnirAU1enW1g-_xRZdHWm8prnA"/>
</application>
</manifest>
这是它在sdk上的外观打印 这就是它在手机上的样子
答案 0 :(得分:3)
您的内容不足以适应屏幕。您可以将布局重力设置为居中以使所有内容居中。
你可以为手机和平板电脑制作自定义布局(7“+ 10”)并尝试重新排序元素以更好地使用房地产
BTW:SDK预览设置为Nexus One,屏幕尺寸要小得多。这就是为什么它在sdk中看起来如此不同。