问题
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"
回答1:
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"
回答2:
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).
来源:https://stackoverflow.com/questions/42487810/how-to-specify-fixed-layout-marginleft-for-smartphones-and-wrap-content-for-tabl