Android 应用程序响应(适合所有屏幕尺寸)
Android application Responsive(Fit for all screen sizes)
我正在开发一个 android 应用程序,它有一个按钮,images.I 需要制作它 responsive.If 我使用更大的设备,如平板电脑,它显示控件非常 small.And 当我在横向模式下使用时,它显示了一半的控件,或者 items.How 我可以克服这个问题并使我的应用程序响应所有 devices.I 附加的我下面的 XML 代码之一。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical"
>
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="125dp"
android:layout_marginTop="50dp"
android:layout_weight="0.01"
android:adjustViewBounds="true"
>
</ImageView>
<LinearLayout
android:id="@+id/layButtonH"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.01"
android:layout_marginTop="20dp"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="@+id/addnew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" ADD NEW "
android:background="@drawable/button_shape"
android:textColor="#FFFFFF"/>
<Button
android:id="@+id/open"
android:background="@drawable/button_shape_cancel"
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" OPEN "
android:textColor="#FFFFFF" />
<Button
android:id="@+id/Register"
android:background="@drawable/button_shape_cancel"
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" LOGIN "
android:textColor="#FFFFFF" />
</LinearLayout>
对于响应式设计采取
1) 不要给出像 125dp 这样的硬编码值,而不是用户 wrap_content 或 match_parent 属性
2) 根据分辨率将图像放在 res drawable 下 OS 拍摄适合其分辨率的图像,例如,对于平板电脑设计,在 res 下创建 drawable-sw600 文件夹并将平板电脑图像放在其下。
3) values->dimension 相同,创建具有特定文件夹名称的不同 dimens 文件。例如用于平板电脑的 values-sw600
4) 使用 ScrollView 控件来避免横向模式下的屏幕切割。
有关更多详细信息和指南,请访问 http://developer.android.com/guide/practices/screens_support.html and http://developer.android.com/training/multiscreen/screendensities.html
您可以从下面提到的资源开始。在设计和开发应用程序时,让应用程序适用于所有屏幕尺寸需要一定的考虑。
您必须对图像进行处理,使它们与不同的屏幕尺寸保持一致。这将解决平板电脑中控件非常小的问题。
此外,在横向模式下,您的小部件似乎超出了屏幕高度。一个快速的解决方案是将 LinearLayout
放在 ScrollView
中,以便它在横向滚动时滚动,您可以看到所有控件。但理想的方式是为横向和纵向模式设置不同的布局。
如果您使用 ScrolLView,代码将如下所示:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Your remaining xml elements -->
</ScrollView>
参考:
我正在开发一个 android 应用程序,它有一个按钮,images.I 需要制作它 responsive.If 我使用更大的设备,如平板电脑,它显示控件非常 small.And 当我在横向模式下使用时,它显示了一半的控件,或者 items.How 我可以克服这个问题并使我的应用程序响应所有 devices.I 附加的我下面的 XML 代码之一。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical"
>
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="125dp"
android:layout_marginTop="50dp"
android:layout_weight="0.01"
android:adjustViewBounds="true"
>
</ImageView>
<LinearLayout
android:id="@+id/layButtonH"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.01"
android:layout_marginTop="20dp"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="@+id/addnew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" ADD NEW "
android:background="@drawable/button_shape"
android:textColor="#FFFFFF"/>
<Button
android:id="@+id/open"
android:background="@drawable/button_shape_cancel"
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" OPEN "
android:textColor="#FFFFFF" />
<Button
android:id="@+id/Register"
android:background="@drawable/button_shape_cancel"
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" LOGIN "
android:textColor="#FFFFFF" />
</LinearLayout>
对于响应式设计采取 1) 不要给出像 125dp 这样的硬编码值,而不是用户 wrap_content 或 match_parent 属性 2) 根据分辨率将图像放在 res drawable 下 OS 拍摄适合其分辨率的图像,例如,对于平板电脑设计,在 res 下创建 drawable-sw600 文件夹并将平板电脑图像放在其下。 3) values->dimension 相同,创建具有特定文件夹名称的不同 dimens 文件。例如用于平板电脑的 values-sw600 4) 使用 ScrollView 控件来避免横向模式下的屏幕切割。 有关更多详细信息和指南,请访问 http://developer.android.com/guide/practices/screens_support.html and http://developer.android.com/training/multiscreen/screendensities.html
您可以从下面提到的资源开始。在设计和开发应用程序时,让应用程序适用于所有屏幕尺寸需要一定的考虑。
您必须对图像进行处理,使它们与不同的屏幕尺寸保持一致。这将解决平板电脑中控件非常小的问题。
此外,在横向模式下,您的小部件似乎超出了屏幕高度。一个快速的解决方案是将 LinearLayout
放在 ScrollView
中,以便它在横向滚动时滚动,您可以看到所有控件。但理想的方式是为横向和纵向模式设置不同的布局。
如果您使用 ScrolLView,代码将如下所示:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Your remaining xml elements -->
</ScrollView>
参考: