如何关闭嵌套布局android的开放时,新的布局? [英] How to close nested layout when open new layout in android?

查看:127
本文介绍了如何关闭嵌套布局android的开放时,新的布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序,在我使用一个包含根布局(invitation_single)和嵌套布局(隐藏)的布局。当我在点击根与根布局工作正常沿着布局嵌套布局显示。
     现在我的输出显示像下面图片

在这里输入的形象描述

但我希望我的输出,
    

这意味着,如果上午点击第一个事件的EVENT2然后同时嵌套布局(是,否,也许按键)需要隐瞒的,但如果我有一个单一的事件则该事件的嵌套布局需要可见,否则,如果我有一个以上的事件意味着我想(当单击第二个事件第一事件隐藏的嵌套布局)来显示我作为第二图像输出。我怎样才能做到这一点。
 我的布局code下面看,

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:ID =@ + ID / invitation_single
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:分=?机器人:dividerVertical
    机器人:dividerPadding =5DP
    机器人:showDividers =中间
    工具:上下文=MainActivity。>    <的ImageButton
        机器人:ID =@ + ID /图像
        机器人:layout_width =50dp
        机器人:layout_height =50dp
        机器人:SRC =@绘制/ ic_action_event/>    <的LinearLayout
        机器人:layout_width =0dp
        机器人:layout_height =50dp
        机器人:layout_weight =1
        机器人:可点击=假
        机器人:可聚焦=真
        机器人:方向=垂直>        <的TextView
            机器人:ID =@ + ID / invitation_title
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:paddingLeft =5DP
            机器人:paddingRight =0dp
            机器人:paddingTop =3DP
            机器人:文字颜色=@彩色/黑白
            机器人:TEXTSIZE =18sp/>        <的TextView
            机器人:ID =@ + ID / invitation_place
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:paddingLeft =5DP
            机器人:paddingRight =0dp
            机器人:文字颜色=@彩色/黑白
            机器人:TEXTSIZE =15sp/>
    < / LinearLayout中>    <的LinearLayout
        机器人:ID =@ + ID /隐藏
        机器人:layout_width =0dp
        机器人:layout_height =50dp
        机器人:layout_marginLeft = - 270dp
        机器人:layout_marginTop =60dp
        机器人:layout_weight =1
        机器人:可点击=真
        机器人:可聚焦=真
        机器人:方向=横向
        机器人:paddingTop =1DP
        机器人:知名度=水涨船高
        机器人:weightSum =3>
        <按钮
            机器人:ID =@ + ID / yesbutton
            机器人:layout_width =30dp
            机器人:layout_height =30dp
            机器人:layout_marginLeft =7DP
            机器人:layout_weight =1
            机器人:背景=@色/蓝
            机器人:文字=是
            机器人:文字颜色=@彩色/黑白>< /按钮>        <按钮
            机器人:ID =@ + ID / nobutton
            机器人:layout_width =30dp
            机器人:layout_height =30dp
            机器人:layout_marginLeft =25dp
            机器人:layout_weight =1
            机器人:背景=@色/蓝
            机器人:文字=否
            机器人:文字颜色=@彩色/黑白>< /按钮>        <按钮
            机器人:ID =@ + ID / buttonmaybe
            机器人:layout_width =30dp
            机器人:layout_height =30dp
            机器人:layout_marginLeft =25dp
            机器人:layout_marginRight =10dp
            机器人:layout_weight =1
            机器人:背景=@色/蓝
            机器人:文字=也许
            机器人:文字颜色=@彩色/黑白>< /按钮>    < / LinearLayout中>
< / LinearLayout中>

我的编程code下面看,

 最后的LinearLayout第一=(的LinearLayout)convertView.findViewById(R.id.invitation_single);
            最终的LinearLayout秒=(的LinearLayout)convertView.findViewById(R.id.hidden);
first.setOnClickListener(新View.OnClickListener(){
                @覆盖
                公共无效的onClick(视图v){
                    开关(v.getId()){
                        案例R.id.invitation_single:
                            second.setVisibility(View.VISIBLE);
                            打破;                    }
                }
            });在上述code我用来显示嵌套布局(隐藏)下方根布局(邀请单)。


解决方案

你有一个小的组事件或事件的数量可以得到pretty长时间?如果第二个选择是真的,那么我会建议看ExpandableListView。看看这个链接,特别是如何在扩大一个新的折叠previously开放的项目: ExpandabeListView自动崩溃

I am developing an android application,In that I am using a Layout that contains a root layout(invitation_single) and nested layout(hidden). When I am on click root layout the nested layout display along with root layout that works fine. now my output is display like below image

but i am expecting my output as,

that means if am click "event2" then simultaneously nested layout(yes,no,maybe buttons) of first "event" needs to hide,but if i have a single event then the nested layout of that event needs to be visible,else if i have more than one event means i want to display my output as second image(nested layout of first"event" hide when click second event). How can i achieve that. my layout code is looking below,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/invitation_single"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="?android:dividerVertical"
    android:dividerPadding="5dp"
    android:showDividers="middle"
    tools:context=".MainActivity">

    <ImageButton
        android:id="@+id/image"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@drawable/ic_action_event" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_weight="1"
        android:clickable="false"
        android:focusable="true"
        android:orientation="vertical">

        <TextView
            android:id="@+id/invitation_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp"
            android:paddingRight="0dp"
            android:paddingTop="3dp"
            android:textColor="@color/black"
            android:textSize="18sp" />

        <TextView
            android:id="@+id/invitation_place"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp"
            android:paddingRight="0dp"
            android:textColor="@color/black"
            android:textSize="15sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/hidden"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_marginLeft="-270dp"
        android:layout_marginTop="60dp"
        android:layout_weight="1"
        android:clickable="true"
        android:focusable="true"
        android:orientation="horizontal"
        android:paddingTop="1dp"
        android:visibility="gone"
        android:weightSum="3">


        <Button
            android:id="@+id/yesbutton"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_marginLeft="7dp"
            android:layout_weight="1"
            android:background="@color/blue"
            android:text="Yes"
            android:textColor="@color/black"></Button>

        <Button
            android:id="@+id/nobutton"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_marginLeft="25dp"
            android:layout_weight="1"
            android:background="@color/blue"
            android:text="No"
            android:textColor="@color/black"></Button>

        <Button
            android:id="@+id/buttonmaybe"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_marginLeft="25dp"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:background="@color/blue"
            android:text="Maybe"
            android:textColor="@color/black"></Button>

    </LinearLayout>


</LinearLayout>

my programming code is looking below,

final LinearLayout first = (LinearLayout) convertView.findViewById(R.id.invitation_single);
            final LinearLayout second = (LinearLayout) convertView.findViewById(R.id.hidden);
first.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    switch (v.getId()) {
                        case R.id.invitation_single:
                            second.setVisibility(View.VISIBLE);
                            break;

                    }
                }


            });

In above code I am used to display nested layout(hidden) immediately below root layout(invitation single).

解决方案

Do you have a small set of events or the number of events could get pretty long? If the second choice is true then I would suggest looking at ExpandableListView. Check out this link particularly on how to collapse the previously open items upon expanding a new one: ExpandabeListView auto collapse

这篇关于如何关闭嵌套布局android的开放时,新的布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆