简体   繁体   English

Android-LinearLayout背景为“上方”视图

[英]Android - LinearLayout Background “over” Views

I am trying to apply a simple gradient background to my main LinearLayout. 我正在尝试将简单的渐变背景应用于我的主要LinearLayout。 My problem is that the background refuses to stay in the background and instead decides to also cover my views (TextViews and Buttons, in this case). 我的问题是背景拒绝停留在背景中,而是决定也覆盖我的视图(在这种情况下为TextViews和Buttons)。 What am I doing wrong/am I missing? 我做错了/我想念什么? Thanks for your help! 谢谢你的帮助!

main layout: 主要布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainLinearLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg_gradient"
android:orientation="vertical" 
>

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Select the PC to communicate with..." />

<TextView
    android:id="@+id/textViewStatus"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Status" />

<RadioGroup
    android:id="@+id/radioGroupDevices"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

</RadioGroup>  

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/btnBack"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="&lt;&lt;" />

    <Button
        android:id="@+id/btnVolDown"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="-" />

    <Button
        android:id="@+id/btnPlayPause"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="|>" />

    <Button
        android:id="@+id/btnVolUp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="+" />

    <Button
        android:id="@+id/btnNext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=">>" />

   </LinearLayout>

</LinearLayout>

drawable/bg_gradient.xml: 绘制/ bg_gradient.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient android:angle="270" android:endColor="#181818" android:startColor="#616161"/>

    <stroke android:width="1dp" android:color="#343434" />
</shape>

Result (Screenshot from Eclipse xml editor, but looks the same on the actual phone) http://s14.directupload.net/images/130415/q8q6hcmn.png 结果(来自Eclipse xml编辑器的屏幕截图,但在实际的电话上看起来相同) http://s14.directupload.net/images/130415/q8q6hcmn.png

As you can see, the text lines and the buttons appear to be at least partially covered by the background. 如您所见,文本行和按钮似乎至少部分被背景覆盖。 I also tried to use a normal black background, but with the same result. 我也尝试使用普通的黑色背景,但结果相同。 All views appear "foggy" behind a black haze. 所有视图在黑色的阴霾后面显得“有雾”。

It seems you are developing for the android version 3 or higher...so in this versions and the versions above the theme is set such as the controls seems to be having transparent background... 似乎您正在为Android 3或更高版本开发...因此在此版本中,已设置了主题之上的版本,例如控件似乎具有透明背景...

try changing the controls(buttons,textviews) background to some hash color values 尝试将控件(按钮,文本视图)的背景更改为一些哈希颜色值

eg:- android:background="#ffaaff" 例如: android:background="#ffaaff"

now you need not to change your code...give it a try as it is... 现在您无需更改代码...直接尝试一下...

for your buttons put this in your code to make them transparent... 为您的按钮将其放入代码中以使其透明...

v.setBackgroundColor(0x0000FF00 );

hope this works for you 希望这对你有用

I do not see your buttons to be polluted by your gradient. 我看不到您的按钮会被渐变污染。 As for the top most text - it's normal as by default TextView background is transparent, so container's bg will be seen thru it. 至于最上面的文本-这是正常的,因为默认情况下TextView背景是透明的,因此可以通过它看到容器的bg。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM