Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中的分段控制与iOS中的类似_Android - Fatal编程技术网

android中的分段控制与iOS中的类似

android中的分段控制与iOS中的类似,android,Android,我想在android中制作一个分段控件(就像在iOS中一样),以便在性别之间切换。android是否提供了这样的小部件 以下是表示: 按如下方式进行尝试: <LinearLayout android:id="@+id/nl_rllayut" android:layout_width="fill_parent" android:layout_height="wrap_content" android:weightSum="1" > <

我想在android中制作一个分段控件(就像在iOS中一样),以便在性别之间切换。android是否提供了这样的小部件

以下是表示:

按如下方式进行尝试:

  <LinearLayout
    android:id="@+id/nl_rllayut"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:weightSum="1" >

    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".5" >

        <Button
            android:id="@+id/nl_btn1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="MALE"
            android:background="@android:color/black"
            android:textColor="@android:color/white" />
    </FrameLayout>

    <FrameLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".5" >

        <Button
            android:id="@+id/nl_btn2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="FEMALE"
            android:background="@android:color/darker_gray"
            android:textColor="@android:color/white" />
    </FrameLayout>
</LinearLayout>

输出:

有办法做到这一点:

<FrameLayout
            android:id="@+id/a4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/a1"
            android:layout_alignRight="@+id/a1"
            android:layout_below="@+id/a3" >


            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:contentDescription="@string/cD"
                android:src="@drawable/signup_17" />

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

                <View
                    android:id="@+id/signup_male"
                    android:layout_width="00dp"
                    android:layout_height="40dp"
                    android:layout_weight="0.50"
                    android:background="@android:color/transparent" />

                <View
                    android:id="@+id/signup_female"
                    android:layout_width="0dp"
                    android:layout_height="40dp"
                    android:layout_weight="0.50"
                    android:background="@android:color/transparent" />
            </LinearLayout>

        </FrameLayout>


唯一的问题是,如果我给这些视图的高度指定填充父视图,它们会占据父视图的整个空间(甚至水平),这很奇怪,我也不知道为什么

为什么不只拥有两个
ImageView
s?因为我不想:3“我不想”不是一个很好的理由。你所描述的最好是通过两种观点来实现的,你的设计在你的问题上似乎有缺陷。这不是答案(无意冒犯),我想知道的主要问题是,有没有可能做我想做的事情?两个图像视图并不适用于所有情况。有时候,我需要一张带有透明视图的图片。不,这不是答案,而是一条评论。ImageView不是视图组,因此不能简单地向其添加其他视图。您可以进行自定义绘图,当然也可以添加侦听器。然后,在您的侦听器中,您可以检查事件的坐标并相应地采取行动。我不想要单独的按钮,我得到的是一张图像作为图形,并希望在其上添加视图。您可以为两个按钮分别创建自己的选择器并根据选择对其进行管理,或者为选定和取消选定的图像获得两张单独的图像。