0

所以我在我的视图上剪辑按钮单击区域时遇到问题。目前我有一个非常简单的视图,在任何动画之前,视图的宽度被限制为其中包含的按钮的大小,即使我告诉要在宽度和高度上都是 fill_parent。

我的动画绘图与 setClipChildren(false) 一起正常工作,但这仍然阻止了按钮被单击。我也正确地移动了实际按钮的视图,因为当其中一个按钮(我在这个动画中有 5 个都独立移动)直接移动到初始起始位置上方时,它可以被点击,我甚至可以正确接收。

这是我用于最外层视图的代码(我有 2 个来模拟以后如何将此视图添加到更大的项目中):

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <com.tests.FancyBottomTab
            android:id="@+id/fancyBottomTab1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="5dp"
            android:gravity="center_horizontal" 
            android:clipChildren="false">

        </com.tests.FancyBottomTab>

    </RelativeLayout>

那么这里是 FancyBottomTab 用作其布局 xml 的内容:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal"
        android:orientation="vertical" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="5dp"
            android:background="@drawable/b1"
            android:paddingBottom="5dp" />

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="5dp"
            android:background="@drawable/b2"
            android:paddingBottom="5dp"  />

       <Button
            android:id="@+id/button3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="5dp"
            android:background="@drawable/b3"
            android:paddingBottom="5dp"  />

        <Button
            android:id="@+id/button4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="5dp"
            android:background="@drawable/b4"
            android:paddingBottom="5dp"  />

        <Button
            android:id="@+id/button5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="5dp"
            android:background="@drawable/b5"
            android:paddingBottom="5dp"  />

        <Button
            android:id="@+id/fancyRedButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:background="@drawable/fancy_red_button"
            android:visibility="visible" />

    </RelativeLayout>

更新:假设动画是宽度为 100dp 的半圆形,并且按钮间隔均匀,视图正确移动。希望这可以解决一些问题并帮助找到解决方案。

再次更新:好的,这次应该有人能帮我找出问题所在,我编辑了背景,使包含按钮的 RelativeLayout 中的 on 是半透明的(下图中的灰色),然后外部 RelativeLayout 的背景是白色的。现在外部的 RelativeLayout 必须保持一个相对布局,以便以后进行布局,但这里是用于它的 XML:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/white"
        android:orientation="vertical" >


        <com.dobango.tests.FancyBottomTab
            android:id="@+id/fancyBottomTab1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="5dp"
            android:clipChildren="false"
            android:gravity="center_horizontal" >

        </com.dobango.tests.FancyBottomTab>

    </RelativeLayout>

这是一个添加了颜色的屏幕截图,应该可以清楚地表明出了什么问题,但我根本看不到它。

在此处输入图像描述

4

1 回答 1

0

好的,所以我不知道为什么要让视图正确显示是绝对必要的,特别是因为我已经在 XML 文件中说了同样的事情,但是这一行完全解决了问题:

   view.setLayoutParams(new LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

如果有人知道为什么我必须将此行放在我的自定义相对布局类中,请发表评论并解释。谢谢。

于 2012-05-22T20:42:37.143 回答