-2

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"
Charuක
  • 12,953
  • 5
  • 50
  • 88
kumar
  • 708
  • 4
  • 15
  • 39

2 Answers2

0

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.

You can try this way

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

for match_parent> <dimen name="your_value">-1dp</dimen>

and set android:layout_marginLeft="@dimen/your_value"

Community
  • 1
  • 1
Charuක
  • 12,953
  • 5
  • 50
  • 88
  • Thanku for repay...but your approach is not working... its giving error as android.view.InflateException: Binary XML file line #57: Can't convert to dimension: type=0x10 – kumar Feb 27 '17 at 15:19
  • @kumar have you given the values in **dp** just giving a value will throw that error, this works for me very well, next double check you have given the values for all your xmls not only for a one – Charuක Feb 27 '17 at 15:20
-1

You Just have to create 5 layouts file for all screen sizes with same name(of layout file) and store it into different folder In (hdpi,mdpi,xhdpi,xxhdpi,xxxhdpi).

Neh Kumari
  • 17
  • 5