[英]Android application Responsive(Fit for all screen sizes)
我正在开发一个具有按钮和图像的android应用程序。我需要使其具有响应性。如果我使用较大的设备(如平板电脑),则显示的控件非常小。而在横向模式下使用时,它会显示一半的控件。或项目。我该如何克服这个问题并使我的应用程序对所有设备做出响应。我在下面附加了我的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可绘制状态下,按照分辨率OS来获取适合其分辨率的图像,例如,用于平板电脑设计,创建drawable-sw600文件夹在res下,将平板电脑图片放在下面。 3)值相同->尺寸创建具有特定文件夹名称的不同尺寸文件。 例如,用于数位板的values-sw600 4)使用ScrollView控件可避免在横向模式下截屏。 有关更多详细信息和指南,请访问http://developer.android.com/guide/practices/screens_support.html和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>
参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.