【问题标题】:How to set transparent background during translate animation android?如何在翻译动画android期间设置透明背景?
【发布时间】:2014-01-10 23:54:34
【问题描述】:

我有以下问题。我有一个 TableLayout 和两个 TableRows。两个 TableRows 都包含两个 ImageButton。单击一个按钮时,我想淡出其他三个按钮并翻译屏幕中心单击的按钮。当它被翻译时,上半部分或下半部分消失了,就像它被另一个表格行隐藏一样。我尝试设置表格行的透明背景,设置 alpha=0,更改布局,还尝试使用 ScaleAnimation,但问题并没有消失。我怎样才能显示消失的一半?我还发布了布局代码和问题所在屏幕的链接。

http://it.tinypic.com/r/1zejhir/5

`

<RelativeLayout
    android:id="@+id/l34"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:layout_alignParentTop="true">
        <ImageButton
            android:id="@+id/four"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="top|right"
            android:src="@drawable/unor"
            android:alpha="0"
            android:onClick="translate"
            android:layout_alignParentLeft="true" />

        <ImageButton
            android:id="@+id/three"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="top|left"
            android:src="@drawable/unor"
            android:alpha="0"
            android:onClick="translate"
            android:layout_alignParentRight="true" />
</RelativeLayout>

<RelativeLayout
    android:id="@+id/l12"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentBottom="true">
        <ImageButton
            android:id="@+id/one"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="top|right"
            android:src="@drawable/unor"
            android:alpha="0"
            android:onClick="translate"
            android:layout_alignParentLeft="true" />

        <ImageButton
            android:id="@+id/two"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="top|left"
            android:src="@drawable/unor"
            android:alpha="0"
            android:onClick="translate"
            android:layout_alignParentRight="true" />
</RelativeLayout>

</RelativeLayout>

`

【问题讨论】:

    标签: android android-layout android-animation


    【解决方案1】:

    使透明

    java代码->imagebtn.setBackgroundColor(Color.TRANSPARENT);

    xml-> android:background="@android:color/transparent"

    【讨论】:

    • 我也试过了,但是不行。 The other buttons disappeared with a fade out animation which set alpha=0, but when the selected button, for example the bottom|right position one, translate at the center I view only the bottom half as shown in the screen I posted.跨度>
    【解决方案2】:

    问题是您想使用其他视图组的“空间”,您的视图绑定到托管视图组(例如 tablerow)。它与透明背景没有任何关系。解决方案是拥有一个包含所有图标的视图组。例如使用RelativeLayout。

    【讨论】:

    • 我尝试了 RelativeLayout 版本,并使用新布局编辑了我的问题。不幸的是没有变化。我也尝试过使用 bringChildToFront() 和 BringToFront() 方法,但没有...
    • 您应该为所有孩子使用一种相对布局,而不是 2 ;)
    • 哇!它现在似乎工作了!我为自己感到羞耻,我只替换了布局名称,但没有删除其他子布局。非常感谢!
    【解决方案3】:

    在values文件夹中创建修改styles.xml文件资源,代码如下

    <item name="android:windowIsTranslucent">true</item>
    
    <item name="android:windowBackground">@android:color/transparent</item>
    
    <item name="android:windowContentOverlay">@null</item>
    
    <item name="android:windowNoTitle">true</item>
    
    <item name="android:windowIsFloating">true</item>
    
    <item name="android:backgroundDimEnabled">false</item>
    

    在 manifest.xml 文件中添加以下步骤,使您的活动变得透明。

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

    【讨论】: