Hello!

For a long time I have been tormented by the question and Google does not give an answer ...

A piece of code:

mViewMain = mInflater.inflate(R.layout.main, null); mLayoutParamsForMain = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, mFlagsForMain, PixelFormat.TRANSLUCENT); mWindowManager.addView(mViewMain, mLayoutParamsForMain); 

All this happens in the Service . I adapt the xml markup purely in landscape orientation and under large-screen tablets. As an example, take the Nexus 10 emulator with a screen of 2560x1600 xhdpi. I expose all sizes to: res/values-w820dp/dimens.xml -land don’t use the res/values-w820dp/dimens.xml prefixes anywhere, as I don’t see the point in this yet.

Next, the markup itself:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main" android:layout_width="wrap_content" android:layout_height="wrap_content"> <LinearLayout android:id="@+id/main_test" android:orientation="horizontal" android:layout_width="@dimen/main_test_width" <!--580dp--> android:layout_height="@dimen/main_test_height"> <!--wrap_content--> </LineareLayout> </RelativeLayout> 

Here, my main_test width is 580dp, in LayoutParams = WRAP_CONTENT .

Now the question: trying to make the width MORE than 580dp - result 0 (as it was and remains). How to remove these indents in the landscape, what is responsible for this ?

Ps putting MATCH_PARENT in LayoutParams with further LayoutParams in xml does not suit me, since filling the entire width, this layout will be deprived of the ability to move in width — OnTouchListener , although it solves this problem completely. It also solves the setting of LayoutParams in px , but again - wondering why, when WRAP_CONTENT it is impossible to increase the width and remain indented ?

enter image description here

While the issue is solved as follows:

 int width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, getResources().getInteger(R.integer.main_width), getResources().getDisplayMetrics()); mLayoutParamsMain = new WindowManager.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, mFlagsForMain, PixelFormat.TRANSLUCENT); 

AND:

 res/values/integers.xml <-- main_width 

For tablets:

 res/values-w820dp/integers.xml <-- main_width 

    1 answer 1

    wrap_content - size, calculated from the required space for displaying content and no more than is required for this. You cannot directly influence this parameter without overriding your own class (and the calculation of this parameter in it).

    In order to visually expand the widget with the wrap_content parameter, you can specify paddings - indents inside the widget, from the border of the widget to its content.