如何为智能手机指定固定的layout_marginLeft,为NavigationDrawer指定平板电脑的wrap_content

时间:2017-02-27 14:08:08

标签: android android-layout android-fragments android-navigation-drawer

我有以下导航抽屉,我想为智能手机提供layout_marginLeft -64dp,为平板电脑提供wrap_content。 请告诉我怎么做?我不想为智能手机和平板电脑创建单独的laytout.xml文件,即我只有一个layout.xml文件。截至目前,我在dimes.xml文件中指定了为智能手机和标签创建的不同维度。

<!-- The navigation drawer -->
<android.support.design.widget.NavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:layout_marginLeft="-64dp"

2 个答案:

答案 0 :(得分:0)

假设您知道如何为multiple screens创建不同的dimes.xml文件(如果您不知道在How to define dimens.xml for every different screen size in android?查看),那么您的问题应该是如何设置使用维度值在特定xml文件中android:layout_marginLeft

你可以试试这种方式

代表wrap_content&gt;     <dimen name="your_value">-2dp</dimen>

代表match_parent&gt; <dimen name="your_value">-1dp</dimen>

并设置android:layout_marginLeft="@dimen/your_value"

答案 1 :(得分:-1)

您只需要为所有具有相同名称(布局文件)的屏幕尺寸创建5个布局文件,并将其存储到不同的文件夹中(hdpi,mdpi,xhdpi,xxhdpi,xxxhdpi)。