I have this RelativeLayout
component and I want to set it to the entire screen width. How can I do that?
我有这个RelativeLayout组件,我想将其设置为整个屏幕宽度。我怎样才能做到这一点?
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?
我试图填充fill_parent以尝试填充整个宽度。但它不起作用。我能做什么?
3 个解决方案
#1
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”/>
#2
For this to work, you have to add android:layout_width
, and android:layout_height
in your layout node
like:
为此,您必须在布局节点中添加android:layout_width和android:layout_height,如:
<RelativeLayout
style="@style/layoutAtendenteBalao"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+atendente/rltAtendenteBalao">
#3
use -1 and -2 for fill_parrent and wrap_content
使用-1和-2表示fill_parrent和wrap_content
Reference: http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#FILL_PARENT
<style name="layoutAtendenteBalao">
<item name="android:layout_width">-1</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>
#1
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”/>
#2
For this to work, you have to add android:layout_width
, and android:layout_height
in your layout node
like:
为此,您必须在布局节点中添加android:layout_width和android:layout_height,如:
<RelativeLayout
style="@style/layoutAtendenteBalao"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+atendente/rltAtendenteBalao">
#3
use -1 and -2 for fill_parrent and wrap_content
使用-1和-2表示fill_parrent和wrap_content
Reference: http://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html#FILL_PARENT
<style name="layoutAtendenteBalao">
<item name="android:layout_width">-1</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>