首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android多屏

Android多屏
EN

Stack Overflow用户
提问于 2017-07-08 16:36:31
回答 2查看 102关注 0票数 0

我有一个问题,在android的多屏幕。

在我读完这个网页后:

https://developer.android.com/guide/practices/screens_support.html developer.android.com/training/multiscreen/screensizes.html

我尝试通过添加最小屏幕宽度布局目录将我的活动更改为多屏幕布局:

布局-sw320dp

布局-sw320dp-land

布局-sw480dp

布局-sw480dp-land

布局-sw600dp

布局-sw600dp-land

布局-sw720dp

布局-sw720dp-land

我的活动:

activity_main.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:id="@+id/activity_main"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@color/background"
          tools:context="com.example.aref.calculator.MainActivity"
          android:orientation="vertical">


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/lin"
    android:orientation="vertical">


    <EditText
        android:id="@+id/etInput"
        android:layout_height="163dp"
        android:background="@android:color/transparent"
        android:cursorVisible="false"
        android:gravity="end|center"
        android:hint="@string/zero"
        android:inputType="numberSigned"
        android:padding="16dp"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:textColor="@android:color/black"
        android:textColorHint="@android:color/darker_gray"
        android:textCursorDrawable="@null"
        android:textSize="50sp"
        android:layout_width="match_parent" />


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="2dp"
        android:orientation="horizontal">

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

            <Button
                android:id="@+id/btnMc"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:background="@drawable/btn_selector"
                android:text="@string/mc" />

            <Button
                android:id="@+id/btnMemory"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector"
                android:text="@string/nullMemory" />

            <Button
                android:id="@+id/btnSeven"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/seven" />

            <Button
                android:id="@+id/btnFour"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/four" />

            <Button
                android:id="@+id/btnOne"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/one" />

            <Button
                android:id="@+id/btnZero"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/zero" />

        </LinearLayout>

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

            <Button
                android:id="@+id/btnMPlus"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:background="@drawable/btn_selector"
                android:text="@string/mPlus" />

            <Button
                android:id="@+id/btnClear"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector1"
                android:text="@string/clear" />

            <Button
                android:id="@+id/btnEight"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/eight" />

            <Button
                android:id="@+id/btnFive"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/five" />

            <Button
                android:id="@+id/btnTwo"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/two" />

            <Button
                android:id="@+id/btnPoint"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector1"
                android:text="@string/point" />

        </LinearLayout>

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

            <Button
                android:id="@+id/btnMMinus"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:background="@drawable/btn_selector"
                android:text="@string/mMinus" />

            <Button
                android:id="@+id/btnAllClear"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector1"
                android:text="@string/AllClear" />

            <Button
                android:id="@+id/btnNine"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/nine" />

            <Button
                android:id="@+id/btnSix"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/six" />

            <Button
                android:id="@+id/btnThree"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector2"
                android:text="@string/three" />

            <Button
                android:id="@+id/btnEqual"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector1"
                android:text="@string/equal" />

        </LinearLayout>

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

            <Button
                android:id="@+id/btnMr"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:background="@drawable/btn_selector"
                android:text="@string/mr" />

            <Button
                android:id="@+id/btnMod"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector3"
                android:text="@string/mod" />

            <Button
                android:id="@+id/btnDiv"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector3"
                android:text="@string/div" />

            <Button
                android:id="@+id/btnMul"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector3"
                android:text="@string/mul" />

            <Button
                android:id="@+id/btnPlus"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector3"
                android:text="@string/plus" />

            <Button
                android:id="@+id/btnMin"
                android:layout_width="@dimen/btn_width_small"
                android:layout_height="@dimen/btn_height_small"
                android:layout_marginLeft="@dimen/btn_marginLeft_marginStart"
                android:layout_marginStart="@dimen/btn_marginLeft_marginStart"
                android:layout_marginTop="@dimen/btn_margin_top"
                android:background="@drawable/btn_selector3"
                android:text="@string/minus" />

        </LinearLayout>


    </LinearLayout>

</LinearLayout>

例如,我的问题是在“布局-sw320dp”中,当我将设备更改为nexus4或nexus5x的布局变得不合适时,我为nexus5x设计布局。

I M A G E:http://s8.picofile.com/file/8299930926/564684.png

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-07-08 16:45:10

您正在设置固定宽度的按钮。这永远不会在各种设备上很好地工作。使用另一种技术。例如,如果你想要4个大小相等的按钮,将每一行作为线性布局,并为它们分配0dp的宽度和1的权重,这样它们就会变得同样大。

票数 0
EN

Stack Overflow用户

发布于 2017-07-08 18:31:16

您可以创建线性布局并使用可在多个屏幕中使用的加权和.so

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44984226

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档