布局xml不适用于较小的设备

时间:2013-02-03 14:44:33

标签: android xml android-layout

我制作了一个Android应用程序,我编写了以下xml代码。它在大型设备中正常显示,但没有显示在较小的设备中,例如galaxy y。所以我想让我的代码动态化,以便它可以在所有设备中显示。

  <?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:orientation="vertical" >

<ImageView
    android:id="@+id/ivReturnedPic"
    android:layout_width="fill_parent"
    android:layout_height="250dp"
    android:layout_gravity="center"
    android:src="@drawable/back" />

<Button
    android:id="@+id/ibtakePic"
    android:layout_width="125dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="click to snap" />

<TextView
    android:id="@+id/tvDisplay"
    android:layout_width="wrap_content"
    android:layout_height="100dp"
    android:layout_gravity="center"
    android:background="#EEEEEE"
    android:gravity="center"
    android:text="Fool Around By  Clicking Test"
    android:textColor="#0000ff"
    android:textSize="35dp" />
<Button
    android:id="@+id/test"
    android:layout_width="344dp"
    android:layout_height="101dp"
    android:text="test" />

1 个答案:

答案 0 :(得分:0)

测试按钮未显示,因为视图中的剩余项目占据整个屏幕。您应该使用ScrollView,以便屏幕变得可滚动并处理不同的屏幕尺寸。

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

  <LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
  </LinearLayout>
</ScrollView>