[英]How I set the width of RelativeLayout to screen width?
我有这个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>
我试图把fill_parent
尝试填充整个宽度。 但这没有用。 我能做什么?
将此布局包含到其他布局时,应进行设置,例如:
<include android:id=”@+id/your_id”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
layout=”@layout/your_layout”/>
为此,您必须在layout node
添加android:layout_width
和android:layout_height
,例如:
<RelativeLayout
style="@style/layoutAtendenteBalao"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+atendente/rltAtendenteBalao">
使用-1和-2作为fill_parrent和wrap_content
参考: 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.