4
votes

I got RelativeLayout in content:

<RelativeLayout xmlns:
    android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:maxWidth="350dp"
    ></RelativeLayout>

android:maxWidth="350dp" doesn't work. With wrap_content for layout_width and layout_height neither works `.

2
Please share screenshot for same what you exactly want? - Nilam Vaddoriya
You got android:layout_width="match_parent" that means your layout will be as alrge in width as it's possible - A. Shevchuk
@A.Shevchuk I changed it for wrap_content but its the same. - Janusz j.
@Januszj., can you clarify what is expected result for you? - A. Shevchuk
I just checked the documentation for RelativeLayout or even ViewGroupp and their isn't an attribute for android:maxWidth. It's been declared per View and not all, so for example the Views EditText and ContraintLayout all have that attribute. - cincy_anddeveloper

2 Answers

4
votes

The documentation for RelativeLayout and even ViewGroup doesn't mention an attribute for android:maxWidth. This attribute, as well maxHeight, are instead declared per View, inside of the attrs.xml file of the Android SDK. So, for example the Views TextView, EditText, ImageView and ContraintLayout, all have that attribute, but Spinner does not. You have to implement complex layouts, create custom ViewGroups that support maxWidth/maxHeight or use multiple layout files with dimension modifiers to achieve the same effect.

2
votes

I realized that maxWidth param for RelativeLayout couldn't and can't work. But it's not recognized as wrong parameter for RelativeLayout by Android Studio UI. Maxwidth param is available for Views and ConstraintLayout so in the solution I will add relative positioning to ConstraintLayout with this documentation .