2017-03-14 90 views
0

我的android应用程序中有一个列表视图。我列出了黑色。我想使布局灰色的背景。但是我不能将整个背景变成灰色,只有部分扩展到灰色,其余部分保持白色。我怎样才能让剩余的部分也是灰色的。 这是用于布局视图的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> 

这里是我的屏幕截图

+0

将颜色设置为父视图而不是列表视图。 –

+0

将android:layout_weight =“1”添加到您的列表视图 –

回答

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> 
+0

它的作用谢谢 –

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" > 

Set,layout_heightmatch_parent它将被固定。

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" >