简体   繁体   English

Android应用程序自适应(适合所有​​屏幕尺寸)

[英]Android application Responsive(Fit for all screen sizes)

I am developing an android application,That has a buttons and images.I need to make it responsive.If i use bigger devices like tablets,it displays the controls very small.And when i used in landscape mode,it displays half of the controls or items.How can i overcome this and make my application responsive to all devices.I attached one of my XML code below. 我正在开发一个具有按钮和图像的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>

For responsive design take 1) Don't give hard code values like as 125dp rather than user wrap_content or match_parent property 2) Put images under res drawable as per resolution OS take images suited for its resolution, eg for tablet design create drawable-sw600 folder under res and put tablet images under it. 对于响应式设计,请采取以下措施:1)不要提供像125dp这样的硬代码值,而不要提供用户wrap_content或match_parent属性2)将图像置于res可绘制状态下,按照分辨率OS来获取适合其分辨率的图像,例如,用于平板电脑设计,创建drawable-sw600文件夹在res下,将平板电脑图片放在下面。 3) Same for values->dimension create different dimens file with specific folder name. 3)值相同->尺寸创建具有特定文件夹名称的不同尺寸文件。 eg values-sw600 which is used for tablet 4) Use ScrollView control for avoiding screen cutting in landscape mode. 例如,用于数位板的values-sw600 4)使用ScrollView控件可避免在横向模式下截屏。 For more details and guideline please visit http://developer.android.com/guide/practices/screens_support.html and http://developer.android.com/training/multiscreen/screendensities.html 有关更多详细信息和指南,请访问http://developer.android.com/guide/practices/screens_support.htmlhttp://developer.android.com/training/multiscreen/screendensities.html

You can start off with below mentioned resources. 您可以从以下提到的资源开始。 Making an app available for all screen sizes needs certain consideration while designing and developing the app. 在设计和开发应用程序时,需要考虑所有屏幕尺寸的应用程序。

You will have to work on your images to make them consistent with different screen sizes. 您将需要处理图像以使其与不同的屏幕尺寸保持一致。 This will solve the issue with very small controls in tablets. 这将通过使用平板电脑中很小的控件来解决此问题。

Also, it looks like in landscape mode your widgets are going beyond the screen height. 同样,在横向模式下,您的小部件看起来超出了屏幕高度。 A quick solution would be to put the LinearLayout within a ScrollView so that it scrolls when in landscape and you see all of your controls. 一种快速的解决方案是将LinearLayout放在ScrollView以便它在横向时滚动并看到所有控件。 But ideal way would be to have different layouts for landscape and portrait modes. 但是理想的方法是为横向和纵向模式设置不同的布局。

If you use ScrolLView the code will look like: 如果使用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>

Ref: 参考:

  1. Design for multiple screens 多屏设计

  2. Supporting different screen sizes 支持不同的屏幕尺寸

  3. Supporting multiple screens 支持多屏

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM