如何在android中制作可扩展的面板布局?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10837746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:10:50  来源:igfitidea点击:

How to make expandable panel layout in android?

androidandroid-layout

提问by IamStalker

I have very complex layout to do in android ?

我在 android 中有非常复杂的布局要做吗?

I need two panels the if one expanded the other is extended and otherwise, i would like to make a behavior like slidingdrawer but because i can have in view only button and nothing else i'm in deep trouble.

我需要两个面板,如果一个扩展另一个扩展,否则,我想做一个像滑动抽屉这样的行为,但因为我只能看到按钮而没有其他任何东西,我陷入了深深的麻烦。

enter image description here

在此处输入图片说明

here is the example of what i need please help, i have spent already 3 days on it, havent found an answer for this.

这是我需要的示例,请帮助,我已经花了 3 天的时间,还没有找到答案。

here is my code`

这是我的代码`

    <RelativeLayout android:id="@+id/imagesContent" android:orientation="vertical" android:layout_alignBottom="@+id/lhsLogo"
                    android:layout_width="wrap_content" android:layout_height="wrap_content">
        <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="3dp"
                   android:src="@drawable/orange_price_tag" android:layout_toLeftOf="@+id/lhsLogo" android:layout_alignBottom="@+id/lhsLogo" />
        <LinearLayout android:layout_centerHorizontal="true" android:orientation="vertical" android:layout_width="wrap_content"
                      android:layout_height="wrap_content">
            <TextView android:layout_width="fill_parent" android:layout_height="0dp" android:text="50%" android:singleLine="false"
                      android:textColor="#ffffff" android:textSize="17dp" android:id="@+id/discountTypeNumbers" android:layout_weight="1" />
            <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="????" android:singleLine="false"
                      android:textColor="#ffffff" android:textSize="14dp" android:id="@+id/discountTypeText" />
        </LinearLayout>
    </RelativeLayout>

    <TextView android:id="@+id/detailsTextContent"
              android:layout_below="@+id/imagesContent"
              android:layout_width="fill_parent"
              android:layout_height="200dp"
              android:textSize="11dp"
              android:layout_marginLeft="10dp"
              android:layout_marginRight="10dp"
              android:scrollbars = "vertical"
              android:layout_marginTop="10dp"
              android:text="some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome
                            textsome textsome textsome textsome textsome"
              android:singleLine="false" />

    <RelativeLayout android:id="@+id/frame"
                    android:background="#ffffff"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:layout_alignParentBottom="true">
        <!--... stuff you want to cover at full-size ...-->
        <LinearLayout
                android:id="@+id/special_details_buttons"
                android:layout_marginTop="5dp"
                android:layout_marginLeft="5dp"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">

            <ImageView android:id="@+id/specialTerms"
                       android:layout_width="wrap_content"
                       android:layout_height="fill_parent"
                       android:layout_marginLeft="2dp"
                       android:src="@drawable/special_terms"  />

            <ImageView android:layout_width="wrap_content"
                       android:layout_height="fill_parent"
                       android:layout_marginLeft="5dp"
                       android:src="@drawable/special_details" />

            <CheckBox android:id="@+id/setFavorite" style="@style/favorites_button" android:button="@drawable/favorites_button"/>

            <ImageView android:id="@+id/acceptTerms"
                       android:src="@drawable/accept_special"
                       android:layout_width="wrap_content"
                       android:layout_height="fill_parent"
                       android:layout_marginLeft="48dp"
                    />
        </LinearLayout>

        <RelativeLayout
                android:layout_below="@+id/special_details_buttons"
                android:layout_width="fill_parent"
                      android:layout_height="wrap_content"
                      android:layout_gravity="bottom"
                      android:orientation="vertical">

            <il.co.package.widgets.WrappingSlidingDrawer
                    android:id="@+id/drawer"
                    android:layout_width="fill_parent"
                    android:layout_height="200dp"
                    android:content="@+id/content"
                    android:handle="@+id/handle">

                <RelativeLayout
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/handle">

                    <ImageView android:id="@+id/slide_handle"
                               android:src="@drawable/expand_open"
                               android:layout_width="170dp"
                               android:layout_height="21dp"
                               android:layout_alignParentRight="true" />
                </RelativeLayout>

                <LinearLayout
                        android:gravity="center"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:background="#ffffff"
                        android:id="@+id/content">
                </LinearLayout>

            </il.co.package.widgets.WrappingSlidingDrawer>
        </RelativeLayout>
    </RelativeLayout>
</RelativeLayout>

`

`

采纳答案by Ronnie

You will have to increase and decrease the height of your layout while animating. See this answer, almost what you need. Android: Expand/collapse animation

在制作动画时,您必须增加和减少布局的高度。看到这个答案,几乎是你需要的。Android:展开/折叠动画