简体   繁体   English

如何使应用程序响应所有Android设备?

[英]How to make application responsive for all android devices?

I am creating one application and I want my application to open without any issue with view,I tried to use weightsum attribute for that but I do not know why it shows different views all time in different devices,check this.. 我正在创建一个应用程序,我希望我的应用程序打开没有任何问题的视图,我试图使用权限属性,但我不知道为什么它在不同的设备中显示不同的视图,检查这..

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:orientation="vertical"
 android:background="@drawable/backgroundgd"
 android:weightSum="100.0"
 >
    <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" 
    android:background="@drawable/another"
    />
    <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" 
    android:background="@drawable/secondpart"
    />
 </LinearLayout>

in bluestack it looks like this 在bluestack中它看起来像这样 在此输入图像描述

Change android:layout_width and android:layout_height to "match_parent" of LinearLayout . android:layout_widthandroid:layout_height更改为LinearLayout "match_parent"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical"
 android:background="@drawable/backgroundgd"
 android:weightSum="100.0">
    <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_cntent"
    android:text="@string/hello_world" 
    android:background="@drawable/another"
    />
    <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" 
    android:background="@drawable/secondpart"
    />
 </LinearLayout>

Give match_parent width and height in container LinearLayout: 在容器LinearLayout中给出match_parent的宽度和高度:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/backgroundgd"
>
    <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" 
    android:background="@drawable/another"
    />
    <TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" 
    android:background="@drawable/secondpart"
    />
</LinearLayout>

Also, you are using weight incorrectly. 此外,您正在使用不正确的重量。

Weight sum and weight is used to divide screen portion equally between some elements. 重量和和重量用于在一些元素之间平均划分屏幕部分。 So if you give weightsum = "3" in container layout, and its 3 children layout mention weight="1", then all three children uses up 33.33% part of container layout. 因此,如果您在容器布局中给予weightsum =“3”,并且其3个子布局提到weight =“1”,则所有三个子容器占用容器布局的33.33%部分。 And at that time width and height are kept as 0 dp according to container layout's orientation. 此时宽度和高度根据容器布局的方向保持为0 dp。

Hi Johnson this example may help you. 嗨约翰逊这个例子可能会帮助你。

 <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:weightSum="5">

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="1" />

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:text="2" />

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="3" />

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

相关问题 适用于所有android设备的响应式设计 - Responsive design for all android devices 如何使我的应用程序在所有设备上可见? - How to make my application visible for all devices? 如何为响应式网站制作Android应用程序 - How to make android application for responsive website 如何使我的应用程序支持所有设备的分辨率 - how to make my application support for all devices resolution 如何使我的应用程序可在所有设备和平板电脑上使用? - How to make my application visibile for all devices and tablets? 如何制作可在手机和平​​板电脑中使用的响应式 Android 应用程序? - How to make responsive Android application which is used in mobile and also in tablet? 如何制作任何可在不同设备中使用的Android应用程序作为UI的一部分 - How to make any android application for use in different devices as aspect of UI 如何使 Font Awesome 图标响应 Android 中的所有屏幕尺寸 - How to make Font Awesome icons responsive with all screen sizes in Android 如何设计适用于所有设备的android应用程序的UI? - How to design UI for android application that will compatible for all devices? 如何在所有Android设备的PhoneGap应用程序中使用日期选择器 - How to have datepicker in PhoneGap application for all android devices
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM