【问题标题】:Design looks perfect on phone but so small on tablet - android studio设计在手机上看起来很完美,但在平板电脑上却很小 - android studio
【发布时间】:2017-07-23 10:27:40
【问题描述】:

我为我的 android 项目制作了这个 xml 文件,该设计在我的手机上看起来很完美,但在我的平板电脑上运行它会使按钮、图像……看起来很小,我很想根据正在运行的设备。

这是我的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    android:fitsSystemWindows="true"
    tools:context="molfix.dev.molfix.Activities.Bvn.BienvenuActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:background="#91d0f0"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="45dp"
            android:background="@drawable/toolbar_bvn"
            android:scrollbars="none"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            android:weightSum="1">
        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.AppBarLayout>

    <Button
        android:layout_width="250dp"
        android:layout_height="55dp"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:background="@drawable/button_inscrip"
        android:id="@+id/b_inscrip"
        android:layout_marginTop="20dp"
        android:layout_below="@+id/b_connex"
        android:layout_centerHorizontal="true" />

    <Button
        android:layout_width="250dp"
        android:layout_height="55dp"
        android:background="@drawable/button_connex"
        android:id="@+id/b_connex"
        android:layout_marginTop="151dp"
        android:layout_below="@+id/appbar"
        android:layout_alignStart="@+id/b_inscrip" />
</RelativeLayout>

【问题讨论】:

    标签: android-layout android-studio


    【解决方案1】:

    您可以尝试可扩展的 dp 而不是 dp/sp 等。这将根据运行的设备调整视图的大小。

    依赖:-

    compile 'com.intuit.sdp:sdp-android:1.0.2'
    

    这样使用:-

    在您的 xml 中将所有“10dp”(您的 dp 值)替换为“dimen/_10sdp”(根据您的 dp 值更改)。

    【讨论】:

    • 它对我不起作用,我是这样使用的:在 values 文件夹中的 dimens.xml 文件中,我插入了这个 55sdp 并在我的 activity_main.xml 我在这个 上使用了这一行
    • 像这样使用 android:layout_height="@dimen/_20sdp" 代替 android:layout_height="20dp"。无需在dimens.xml中添加
    【解决方案2】:

    您必须为多屏幕设计您的 xml。对于支持的选项卡,您应该创建 layout-sw600dp 布局,这将支持 7 英寸平板电脑,对于 10 英寸平板电脑,请创建 layout-sw720dp。在 res 文件夹中创建这些布局后,将您的 xml 复制并粘贴到该文件夹​​中,并根据您的要求为视图提供大小。

    【讨论】:

    • 我不明白如何在 res 文件夹中创建这些文件??!
    • 右键单击 res 文件夹单击新建->单击布局资源文件并命名 layout-sw600dp 并创建 layout-sw720dp。之后将布局 xmls 文件复制到这些文件夹 layout-sw600dp 和 layout-sw720dp 中。根据您的要求应用您的视图大小。
    猜你喜欢
    • 1970-01-01
    • 2020-12-31
    • 2021-09-21
    • 1970-01-01
    • 2019-09-24
    • 2018-12-23
    • 1970-01-01
    • 2018-12-01
    • 2023-04-07
    相关资源
    最近更新 更多