设计在手机上看起来很完美但在平板电脑上却很小 - 安卓工作室

时间:2017-07-23 10:27:40

标签: android-layout android-studio

我为我的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>

2 个答案:

答案 0 :(得分:1)

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

相关性: -

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

像这样使用: -

用xml中的“dimen / _10sdp”替换所有“10dp”(你的dp值)(根据你的dp值改变)。

答案 1 :(得分:0)

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