2014-09-18 81 views
0

我有一個ListView。在每一行中,我都有一個LinearLayout其中包含項目。 LinearLayout具有10dp的layout_margin。按下時,我已將其放置在選擇器背景上。但問題是,在10dp的邊界邊緣出現橙色背景色,而LinearLayout黑色背景內出現正確。LinearLayout按下時沒有邊框顏色

我怎麼能刪除邊緣的橙色背景出現?

選擇

<item android:state_pressed="true"> 
    <shape> 
     <gradient android:angle="90" android:startColor="@color/negro" android:endColor="@color/negro" /> 
    </shape> 
</item> 

    <item android:state_enabled="true"> 
    <shape> 
     <gradient android:angle="90" android:startColor="@color/grisOscuro" android:endColor="@color/grisOscuro" /> 
    </shape> 
</item> 

XML

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_margin="10dp" 
    android:background="@color/black" 
    android:orientation="horizontal"> 

<LinearLayout 
    android:baselineAligned="false" 
    android:id="@+id/fondoListviewRow" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/grey" 
    android:orientation="horizontal"> 

... 

</LinearLayout> 

代碼

holderName.fondo.setBackgroundResource(R.drawable.listview_negro);

+0

你有一個橙色的背景某處名單的背後? – 2014-09-18 16:55:57

+0

不,這是在LinearLayout被按下時創建的橙色背景 – user4152 2014-09-18 16:57:41

+0

,橙色只出現在邊緣的某個部分?或者完整的10dp是橙色的?這將是很好,如果你可以把截圖或東西 – 2014-09-18 17:01:56

回答

0

我認爲你的觀點背後有一個橙色背景。

填充

是邊界內的空間,邊框和實際視圖的內容之間。請注意,填充完全圍繞內容:頂部,底部,右側和左側(可以獨立)有填充。

邊距

是邊界外面的空間中,邊界和其它元件旁邊此視圖之間。請注意,像填充一樣,邊距完全圍繞內容:頂部,底部,右側和左側都有邊距。

嘗試使用android:padding =「10dp」insted。它應該解決你的問題。

編輯:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    android:background="#FF0000" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_margin="10dp" 
     android:background="#00FF00" > 
    </LinearLayout> 
</LinearLayout> 

上面的代碼給了我

enter image description here

+0

我希望LinearLayout具有保證金頂部,底部,左側和右側10dp – user4152 2014-09-18 17:15:56

+0

如果你想保證金,也很好。但它將是透明的,並且背景視圖中的任何顏色都將反映在邊距中。在你的情況下,它似乎有橙色背景,所以邊距是橙色的。 – 2014-09-18 17:21:50

+0

有沒有解決辦法? – user4152 2014-09-18 21:16:11

0

根據您對問題的描述,我相信您應該在應用程序» android:theme下,根據您的應用程序清單中選擇的應用程序切換或更改應用程序的主題。樣式可以在res »的值下找到。或者你應該重新定義與感興趣的元素相關的樣式。

之前深挖此,切換主題:

android:theme="@android:style/Theme.Black" 

android:theme="@android:style/Theme.Light" 

android:theme="@android:style/Theme.NoTitleBar" 

...看看會發生什麼。後者顯示沒有操作欄。