Layout issue: SliderDrawer does not fill parent width

I am using SliderDrawer in Android. Inside the box there is a layout that contains a bloated layout. Here's the end result:

enter image description here

Please note that the contents of the box (in gray) does not occupy the entire width of the parent (black area).

Here's the box code (main_layout.xml):

[UPDATE 2, all code added:]

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <LinearLayout android:id="@+id/banner" android:orientation="horizontal"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:gravity="center" android:padding="3px">
    <ImageView android:src="@drawable/title"
      android:layout_width="wrap_content" android:layout_height="wrap_content" />
    <TextView android:layout_width="wrap_content" android:text="@string/title"
      android:layout_height="wrap_content" android:textSize="18sp"
      android:gravity="center_vertical" android:paddingLeft="4px"
      android:textStyle="bold" />
  </LinearLayout>
  <LinearLayout android:layout_below="@id/banner" android:id="@+id/middle" android:orientation="vertical"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <View android:layout_width="fill_parent" android:layout_height="1dip"
      android:background="#FF555555" />
    <ListView android:id="@android:id/list" android:layout_width="fill_parent"
      android:layout_height="fill_parent" android:padding="3px"
      android:layout_weight="1" />
    <TextView android:id="@android:id/empty" android:layout_width="fill_parent"
      android:layout_height="fill_parent" android:text="@string/no_items"
      android:padding="3px" android:layout_weight="1" />
  </LinearLayout>
  <LinearLayout android:id="@+id/LinearLayout01" android:layout_alignParentBottom="true"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:orientation="vertical" android:gravity="center_horizontal|bottom">
    <SlidingDrawer android:id="@+id/drawer" android:background="#22222222" 
      android:layout_height="110dip" android:handle="@+id/handle"
      android:content="@+id/media_player_container" android:layout_width="fill_parent">
      <ImageView android:id="@+id/handle" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:src="@drawable/tray" android:scaleType="centerCrop"/>
      <LinearLayout android:id="@+id/media_player_container"
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:gravity="bottom|center_horizontal" />
    </SlidingDrawer>
  </LinearLayout>
</RelativeLayout>

Here's the code for the overestimated area (media_player_container.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"   android:gravity="bottom|center_horizontal" android:orientation="vertical"  android:background="#FF555555" android:padding="3px">
  <SeekBar android:id="@+id/progress" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingBottom="3px" android:progress="1000" />
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"  android:orientation="horizontal">
    <ImageButton android:id="@+id/speakerhandset" android:src="@drawable/handset" android:layout_width="60dip" android:layout_height="wrap_content" android:scaleType="center"/>
    <ImageButton android:id="@+id/rewind" android:src="@android:drawable/ic_media_rew" android:layout_width="60dip" android:paddingRight="3px" android:layout_height="wrap_content" android:scaleType="center"/>
    <ImageButton android:id="@+id/play" android:src="@android:drawable/ic_media_play" android:layout_width="60dip" android:paddingRight="3px" android:layout_height="wrap_content" android:scaleType="center"/>
    <ImageButton android:id="@+id/pause" android:src="@android:drawable/ic_media_pause" android:layout_width="60dip" android:paddingRight="3px" android:layout_height="wrap_content" android:visibility="gone"  android:scaleType="center"/>
    <ImageButton android:id="@+id/fastforward" android:src="@android:drawable/ic_media_ff" android:layout_width="60dip" android:paddingRight="3px" android:layout_height="wrap_content" android:scaleType="center"/>
  </LinearLayout>
</LinearLayout>

Can you tell me what I'm doing wrong?

[Update 1] Here is the code (inside onCreate ()) where I am inflating the layout:

LinearLayout container = (LinearLayout) this.findViewById(R.id.media_player_container);

LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout layout = (LinearLayout) layoutInflater.inflate(R.layout.media_player, null, false);
container.addView(layout);
+3
source share
4 answers

, , , , media_player_container. (, View ) , , .

:

LinearLayout container = (LinearLayout) this.findViewById(R.id.media_player_container);

LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout layout = (LinearLayout) layoutInflater.inflate(R.layout.media_player, null, false);
container.addView(layout);

:

View.inflate(this, R.layout.media_player, 
        (ViewGroup) findViewById(R.id.media_player_container)

, ( , , ). , , , ( , ).

+6

LayoutParams.

container.addView(layout, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
+2

layoutHeight . FillParent, .

+1
<SlidingDrawer android:id="@+id/drawer" android:padding="10dip" android:background="#22222222" android:layout_height="110dip" android:handle="@+id/handle" android:content="@+id/media_player_container" android:layout_width="fill_parent">

: padding = "10dip". , 10dip . , :

android:paddingTop="10dip"
android:paddingBottom="10dip"
+1

Source: https://habr.com/ru/post/1789025/


All Articles