如何为智能手机指定固定的layout_marginLeft,为NavigationDrawer指定平板电脑的wrap_content [英] How to specify fixed layout_marginLeft for smartphones and wrap_content for tablet for NavigationDrawer

查看:102
本文介绍了如何为智能手机指定固定的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"

推荐答案

假设您知道如何为如何为android中每个不同的屏幕尺寸定义dimens.xml?)您的问题应该是如何在使用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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆