Search code examples
androidwidthscreenandroid-relativelayoutresolution

How I set the width of RelativeLayout to screen width?


I have this RelativeLayout component and I want to set it to the entire screen width. How can I do that?

atendente.xml

<?xml version="1.0" encoding="utf-8"?>
<merge
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

<RelativeLayout
    style="@style/layoutAtendenteBalao"
    android:id="@+atendente/rltAtendenteBalao">

styles.xml

<style name="layoutAtendenteBalao">
     <item name="android:layout_width">fill_parent</item>
     <item name="android:layout_height">210px</item>
     <item name="android:layout_alignParentRight">true</item>
     <item name="android:layout_alignParentBottom">true</item>
     <item name="android:layout_marginRight">176px</item>
     <item name="android:layout_marginBottom">140px</item>
     <item name="android:background">@drawable/borda_balao</item>
     <item name="android:paddingLeft">15dp</item>
     <item name="android:paddingRight">15dp</item>
     <item name="android:paddingTop">10dp</item>
     <item name="android:paddingBottom">10dp</item>
</style>

I have tried to put fill_parent to try to fill the entire width. But it does not worked. What can I do?


Solution

  • You should set it when you including this layout to other, like this:

    <include android:id=”@+id/your_id”
             android:layout_width=”match_parent”
             android:layout_height=”match_parent”
             layout=”@layout/your_layout”/>