我有一个具有两个子布局的RelativeLayout。我们称之为rel1和rel2。 Rel1在顶部有一个标题。然后在中心的个人资料图片。和底部的两个水平放置的按钮。如何在点击时隐藏布局
Rel2有一个listview。 Rel2在父布局的底部对齐。 Rel2占用屏幕的50%,最初不可见。 当我点击rel1中的一个按钮时,rel2变得可见。 因为rel2占据了屏幕的一半,所以rel1的上半部分是可见的,rel1的下半部分被rel2覆盖。
我的要求是,当我点击rel1的上半部分(不包括rel2)时,rel2应该隐藏。
我该怎么做。我应该在rel1布局上添加onclick监听器。如果我在rel1上添加onclick,当点击rel1布局的子项时会发生什么。将点击事件发送给其子女或rel1 ..
请帮忙。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible" >
<RelativeLayout
android:id="@+id/rel1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="23dp"
android:paddingTop="12dp" >
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:ellipsize="end"
android:gravity="center_horizontal"
android:maxLines="1"
android:singleLine="true"
android:text="Title"
android:textSize="20sp" />
<ImageView
android:id="@+id/center_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/Image"
android:contentDescription="center IMage" />
<LinearLayout
android:id="@+id/buttonView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:baselineAligned="false"
android:orientation="horizontal" >
<ImageButton
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginRight="1dp"
android:background="@drawable/button1"
android:contentDescription="@string/str_avoid_warning"/>
<ImageButton
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginLeft="1dp"
android:background="@drawable/button2"
android:contentDescription="@string/str_avoid_warning"/>
</LinearLayout>
<RelativeLayout
android:id="@+id/rel2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:visibility="gone">
<ListView
android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="@android:color/transparent"
android:fadingEdgeLength="7dp"
android:overScrollMode="never"
android:divider="@android:color/transparent"
android:dividerHeight="10.0sp"
android:requiresFadingEdge="vertical">
</ListView>
</RelativeLayout>
</RelativeLayout>
使用它后面的match_parent视图,并添加点击监听到它:) –
我也想加入比赛父透明布局说REL3,并使它当rel2变得可见时,可见其他明智的消息,并增加了onclick监听器。只是不确定它是否是一个好主意,我的意思是它只是黑客。我想知道我是否可以找到更好的解决方案 –
有令人毛骨悚然的解决方案,如在所有视图中添加touchlistener并听取它。但是看不见的布局非常整齐。或者,如果您在父视图和子视图上都有onclick监听器,则应在对话框 –