如何更改完整布局的背景

时间:2017-03-14 06:19:06

标签: android android-layout listview android-linearlayout

我的Android应用程序中有一个列表视图。我给黑色列表。我想制作布局灰色的背景。但是我无法将完整的背景变为灰色,只有部分扩展到哪个列表变为灰色,其余部分保持白色。如何使剩余部分也变灰。  这是listview布局的xml代码。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/main_color_grey_500"
android:orientation="vertical" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="97dp" >

    <ImageView
        android:id="@+id/expandable_lv_social_background_image"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@string/cd_main_image"
        android:scaleType="centerCrop"
        android:src="@drawable/expandable_social_background_image" />


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical" >

        <ImageView
            android:id="@+id/expandable_lv_social_image"
            android:layout_width="64dp"
            android:layout_height="64dp"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="40dp"
            android:layout_marginRight="24dp"
            android:layout_marginTop="16dp" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:layout_marginLeft="4dp"
            android:gravity="center_vertical"
            android:orientation="vertical" >

            <sampleapp.kodspider.com.sampleapp.font.RobotoTextView
                android:id="@+id/expandable_lv_social_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="6dp"
                android:text="Sample App"
                android:textColor="@android:color/white"
                android:textSize="16sp"
                app:typeface="robotoLight" />

            <sampleapp.kodspider.com.sampleapp.font.RobotoTextView
                android:id="@+id/expandable_lv_social_place"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Stage Shows"
                android:textColor="@android:color/white"
                android:textSize="12sp"
                app:typeface="robotoLight" />
         </LinearLayout>
       </LinearLayout>
      </RelativeLayout>

    <View
    android:id="@+id/divider_top"
    android:layout_width="match_parent"
    android:layout_height="3dp"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/imageView1"
    android:background="@color/material_light_yellow_600" />

    <sampleapp.kodspider.com.sampleapp.view.AnimatedExpandableListView
    android:id="@+id/expandable_lv_social_list_view"
    android:background="@drawable/com_facebook_tooltip_black_background"

    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    </sampleapp.kodspider.com.sampleapp.view.AnimatedExpandableListView>



</LinearLayout>

这是我的屏幕截图

3 个答案:

答案 0 :(得分:1)

将layout_height wrap_content更改为match_parent

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/main_color_grey_500"
    android:orientation="vertical" >
    .
    .
    .
    </LinearLayout>

答案 1 :(得分:1)

在您的父级LinearLayout中,替换为:

 <?xml version="1.0" encoding="utf-8"?>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="@color/main_color_grey_500"
  android:orientation="vertical" >

有了这个:

   <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parentt"
    android:background="@color/main_color_grey_500"
    android:orientation="vertical" >

layout_height设置为match_parent,它将被修复。

答案 2 :(得分:1)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/main_color_grey_500"
android:orientation="vertical" >