本文介绍了如何为智能手机指定固定的layout_marginLeft,为NavigationDrawer指定平板电脑的wrap_content的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的导航抽屉,我想将layout_marginLeft设置为-64dp(对于智能手机),将wrap_content设置为平板电脑.我不想为智能手机和平板电脑创建单独的laytout.xml文件,即我只有一个layout.xml文件.到目前为止,我正在为智能手机和标签创建的dimes.xml文件中指定其他尺寸.

I have the below navigation drawer and I want to give layout_marginLeft as -64dp for smartphones and wrap_content for tablets.Please let me know how to do that?I don't want to create separate laytout.xml files for smartphone and tablets i.e I have only one layout.xml file. As of now I am specifying different dimension in dimes.xml files which are created for smartphones and tabs.

<!-- 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"

推荐答案

假设您知道如何为多个屏幕(如果您不知道在)您的问题应该是如何在使用dimen值的特定xml文件.

Assuming that you know how to create different dimes.xml files for multiple screens (If you don't know that have a look in How to define dimens.xml for every different screen size in android?) your problem should be how to set android:layout_marginLeft in the specific xml file using dimen value.

您可以尝试这种方式

对于> <dimen name="your_value">-2dp</dimen>

for wrap_content> <dimen name="your_value">-2dp</dimen>

对于><dimen name="your_value">-1dp</dimen>

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

这篇关于如何为智能手机指定固定的layout_marginLeft,为NavigationDrawer指定平板电脑的wrap_content的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-07 05:13