簡體   English   中英

如何將RelativeLayout的寬度設置為屏幕寬度?

[英]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_widthandroid: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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM