2013-06-21 52 views
0

我有以下模板更改背景顏色動態和使用邊界

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

    <RelativeLayout 
     android:id="@+id/layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="5dp"> 

     <ImageView 
      android:id="@+id/category_starred_icon" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/rating_not_important" 
      android:contentDescription="@string/app_name" /> 

     <TextView 
      android:id="@+id/category_name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_toRightOf="@id/category_starred_icon" 
      android:textIsSelectable="false" 
      android:textSize="18sp" 
      android:paddingLeft="5dp" 
      android:paddingTop="5dp" 
      android:paddingRight="5dp" 
      android:textColor="@android:color/white" 
      android:hint="@string/category" /> 
    </RelativeLayout> 

</LinearLayout> 

我得到一個警告This RelativeLayout layout or its LinearLayout parent is possibly useless; transfer the background attribute to the other view,我想解決這個問題,但我有後續的問題,我在的LinearLayout邊框就像是一個陰影,但是當我改變背景顏色在我的代碼

mLayout.setBackgroundColor(Color.paseColor(mColorString)); 

我失去了邊界,我怎麼能解決警告不用其他失去了邊界,主要的問題是背景顏色是動態

+1

你可以刪除線性佈局,只使用相對佈局,並將'android:background =「@ drawable/borders」'設置爲相對佈局 – Raghunandan

+0

是的,但我需要同時顯示'android:background =「@ drawable/borders」 '和backgroundColor設置代碼 – rkmax

+0

我不認爲它可能爲相同的佈局 – Raghunandan

回答

0

看一看這樣的:​​

這是其它組織可繪製在圖層列表(一個在另一個之上)的繪製。有了它,您可以使用其他可繪圖,如形狀,以您想要的方式定義邊框和背景。

我現在無法做出完整的答案,但是如果您搜索這個,我相信您可以做到。當我有更多時間的時候,如果你還沒有發現如何解決這個問題,我可能會回來幫助你。