【问题标题】:Relative Layout background not filling all the space相对布局背景没有填满所有空间
【发布时间】:2011-12-28 15:47:30
【问题描述】:

我有一个带有背景图像的相对布局,但我希望图像填充所有布局空间,我认为这是一个填充问题,我设置为 -1dip,这不起作用。 同样在将我的填充设置为 -1dip 之前,当我使用分层查看器检查填充时。 这是我的xml

<RelativeLayout
        android:id="@+id/relativeLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/gridView"
        android:background="@drawable/tool_bar"
        android:gravity="center"
       >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/locate" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/imageView1"
            android:src="@drawable/orbit" />

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/imageView2"
            android:src="@drawable/search" />

        <ImageView
            android:id="@+id/imageView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/imageView3"
            android:src="@drawable/snap" />

        <ImageView
            android:id="@+id/imageView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/imageView4"
            android:src="@drawable/profile" />
    </RelativeLayout>
thanks

【问题讨论】:

    标签: android background padding android-relativelayout


    【解决方案1】:

    我遇到了同样的问题。我认为默认情况下,RelativeLayout 不会将背景扩展到其尺寸。

    最终通过以下方式使用内部视图:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="300px"
    android:layout_height="204px">
        <View 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"       
        android:background="@android:color/white"/> //Or whatever background you pick
    </RelativeLayout>
    

    不是我希望的解决方案,而是一个解决方案。

    【讨论】:

      【解决方案2】:
       <RelativeLayout
          android:id="@+id/relativeLayout2"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:background="@drawable/tool_bar"
         >  
      

      应该做我假设的伎俩

      【讨论】:

        【解决方案3】:

        如果你想按宽度和高度填充所有空间,请使用 FILL_PARENT 或者如果你想像填充宽度而不是高度一样填充它们,那么将高度设置为 wrap_content 或者如果你想填充高度而不是宽度然后将 wrap_content 设置为宽度

        像这里它会填满两者

        <RelativeLayout
                android:id="@+id/relativeLayout2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_below="@+id/gridView"
                android:background="@drawable/tool_bar"
                android:gravity="center"
               >
        </RelativeLayout>
        

        【讨论】:

        • 我希望背景图像填充相对布局空间。不是填满整个屏幕的相对布局
        【解决方案4】:

        我认为您希望将图像填充到相对布局。 你试一下。它可能对你有帮助。 fill_parent

        <ImageView
                    android:id="@+id/any_image"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:src="@drawable/profile_you" />
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-07-17
          • 2020-12-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多