RecycleView Header all In One(标题+列表视图+页脚)

时间:2015-09-08 14:23:58

标签: android material-design android-recyclerview

我的标题有问题,我想要包括所有,因为我想要一个页脚静态。

我尝试显示:

  • 屏幕3.7显示正确

  • 屏幕> 4.0显示不正确

enter image description here

我的适配器(仅将标题填满页脚)

   if (viewType == TYPE_HEADER) {

            View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.header,parent,false); //Inflating the layout

            ViewHolder vhHeader = new ViewHolder(v,viewType,context); //Creating ViewHolder and passing the object of type view

            return vhHeader; //returning the object created


        }

我的XML Header.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" tools:context="com.onpocket.alcover.Fragment_0_6"
    android:orientation="vertical">

    <!-- TODO: Update blank fragment layout -->

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="178dp">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@drawable/contenedor_img_2_1_6_3"
            android:id="@+id/l1">

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="0.3" >

                <de.hdodenhof.circleimageview.CircleImageView
                    android:layout_width="70dp"
                    android:layout_height="70dp"
                    android:src="@drawable/barra_lateral_img_0_1"
                    android:layout_marginLeft="16dp"
                    android:layout_marginTop="38dp"
                    android:id="@+id/circleView"
                    android:adjustViewBounds="false" />
            </LinearLayout>

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="0.9"
                android:background="#af000000"
                android:gravity="center_vertical"
                android:focusableInTouchMode="false"
                android:id="@+id/l3"
                android:focusable="false">

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="15dp"
                    android:layout_height="match_parent" />

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center_vertical">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textColor="#ffffff"
                        android:text="text"
                        android:textSize="14sp"
                        android:textStyle="bold"
                        android:id="@+id/name"/>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="text"
                        android:id="@+id/email"
                        android:textColor="#ffffffff" />
                </LinearLayout>

            </LinearLayout>

        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/scrollView2" >

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:paddingTop="10dp">

                    <LinearLayout
                        android:orientation="horizontal"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:gravity="center_vertical" >

                        <LinearLayout
                            android:orientation="horizontal"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="1" >

                            <LinearLayout
                                android:orientation="horizontal"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_weight="1" />

                            <LinearLayout
                                android:orientation="horizontal"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_weight="0.75" >

                                <ImageView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:id="@+id/imageView6"
                                    android:src="@drawable/barra_lateral_img_0_2"
                                    android:adjustViewBounds="true" />
                            </LinearLayout>

                            <LinearLayout
                                android:orientation="horizontal"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_weight="1.3" />
                        </LinearLayout>

                        <LinearLayout
                            android:orientation="horizontal"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="0.2"
                            android:gravity="center_vertical" >

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:textAppearance="?android:attr/textAppearanceMedium"
                                android:text="@string/lateral_inicio"
                                android:id="@+id/textView14"
                                android:textColor="#010001" />
                        </LinearLayout>
                    </LinearLayout>

                    <LinearLayout
                        android:orientation="vertical"
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/color_0_0"
                        android:layout_marginTop="10dp"
                        android:layout_marginBottom="10dp" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:paddingTop="10dp">

                    <LinearLayout
                        android:orientation="horizontal"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:gravity="center_vertical" >

                        <LinearLayout
                            android:orientation="horizontal"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="1" >

                            <LinearLayout
                                android:orientation="horizontal"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_weight="1" />

                            <LinearLayout
                                android:orientation="horizontal"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_weight="0.75" >

                                <ImageView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:id="@+id/imageView7"
                                    android:src="@drawable/barra_lateral_img_0_3"
                                    android:adjustViewBounds="true" />
                            </LinearLayout>

                            <LinearLayout
                                android:orientation="horizontal"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_weight="1.3" />
                        </LinearLayout>

                        <LinearLayout
                            android:orientation="horizontal"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="0.2"
                            android:gravity="center_vertical" >

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:textAppearance="?android:attr/textAppearanceMedium"
                                android:text="@string/lateral_idiomas"
                                android:id="@+id/textView15"
                                android:textColor="#010001" />
                        </LinearLayout>
                    </LinearLayout>

                    <LinearLayout
                        android:orientation="vertical"
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/color_0_0"
                        android:layout_marginTop="10dp"
                        android:layout_marginBottom="10dp" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:paddingTop="10dp"
                    android:paddingBottom="8dp" >

                    <LinearLayout
                        android:orientation="horizontal"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:gravity="center_vertical" >

                        <LinearLayout
                            android:orientation="horizontal"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="1" >

                            <LinearLayout
                                android:orientation="horizontal"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_weight="1" />

                            <LinearLayout
                                android:orientation="horizontal"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_weight="0.75" >

                                <ImageView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:id="@+id/imageView8"
                                    android:src="@drawable/barra_lateral_img_0_4"
                                    android:adjustViewBounds="true" />
                            </LinearLayout>

                            <LinearLayout
                                android:orientation="horizontal"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_weight="1.3" />
                        </LinearLayout>

                        <LinearLayout
                            android:orientation="horizontal"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="0.2"
                            android:gravity="center_vertical" >

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:textAppearance="?android:attr/textAppearanceMedium"
                                android:text="@string/lateral_contacto"
                                android:id="@+id/textView16"
                                android:textColor="#010001" />
                        </LinearLayout>
                    </LinearLayout>

                    <LinearLayout
                        android:orientation="vertical"
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/color_0_0"
                        android:layout_marginTop="10dp"
                        android:layout_marginBottom="10dp" />
                </LinearLayout>

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:paddingTop="10dp"
                    android:paddingBottom="8dp" >

                    <LinearLayout
                        android:orientation="horizontal"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:gravity="center_vertical" >

                        <LinearLayout
                            android:orientation="horizontal"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="1" >

                            <LinearLayout
                                android:orientation="horizontal"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_weight="1" />

                            <LinearLayout
                                android:orientation="horizontal"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_weight="0.75" >

                                <ImageView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:id="@+id/imageView9"
                                    android:src="@drawable/barra_lateral_img_0_5"
                                    android:adjustViewBounds="true" />
                            </LinearLayout>

                            <LinearLayout
                                android:orientation="horizontal"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:layout_weight="1.3" />
                        </LinearLayout>

                        <LinearLayout
                            android:orientation="horizontal"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_weight="0.2"
                            android:gravity="center_vertical" >

                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:textAppearance="?android:attr/textAppearanceMedium"
                                android:text="@string/lateral_notificaciones"
                                android:id="@+id/textView17"
                                android:textColor="#010001" />
                        </LinearLayout>
                    </LinearLayout>

                    <LinearLayout
                        android:orientation="vertical"
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/color_0_0"
                        android:layout_marginTop="10dp"
                        android:layout_marginBottom="10dp" />
                </LinearLayout>
            </LinearLayout>
        </ScrollView>
    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@color/color_0_0"
            android:layout_marginBottom="10dp" />

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="fill_parent"
            android:layout_height="60dp"
            android:id="@+id/linearLayout10" >

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="10dp"
                android:layout_height="match_parent"></LinearLayout>

            <ImageButton
                android:layout_width="32dp"
                android:layout_height="wrap_content"
                android:id="@+id/imageButton6"
                android:src="@drawable/barra_lateral_img_0_6"
                android:layout_weight="1"
                android:background="@null"
                android:scaleType="fitCenter"
                android:layout_margin="12dp"
                android:tag="facebook"
                android:onClick="selectItem" />

            <ImageButton
                android:layout_width="32dp"
                android:layout_height="wrap_content"
                android:id="@+id/imageButton7"
                android:src="@drawable/barra_lateral_img_0_7"
                android:layout_weight="1"
                android:background="@null"
                android:scaleType="fitCenter"
                android:layout_margin="12dp"
                android:tag="twitter"
                android:onClick="selectItem" />

            <ImageButton
                android:layout_width="32dp"
                android:layout_height="wrap_content"
                android:id="@+id/imageButton8"
                android:src="@drawable/barra_lateral_img_0_8"
                android:layout_weight="1"
                android:background="@null"
                android:scaleType="fitCenter"
                android:layout_margin="12dp"
                android:tag="linkedin"
                android:onClick="selectItem" />

            <ImageButton
                android:layout_width="32dp"
                android:layout_height="wrap_content"
                android:id="@+id/imageButton9"
                android:src="@drawable/barra_lateral_img_0_9"
                android:layout_weight="1"
                android:background="@null"
                android:scaleType="fitCenter"
                android:layout_margin="12dp"
                android:tag="blog"
                android:onClick="selectItem" />

            <ImageButton
                android:layout_width="36dp"
                android:layout_height="wrap_content"
                android:id="@+id/imageButton10"
                android:layout_weight="1"
                android:background="@null"
                android:scaleType="fitCenter"
                android:layout_margin="5dp"
                android:tag="youtube"
                android:onClick="selectItem" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>


    <!--
    <?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="178dp"
        android:orientation="vertical"
        android:weightSum="1"
        android:background="@drawable/contenedor_img_2_1_6_3" android:scaleType="centerCrop">



        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="56dp"
            android:orientation="vertical"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="false"
            android:layout_alignParentStart="true"
            android:background="@color/opacity"
            android:gravity="center_vertical">

            <TextView
                android:id="@+id/name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="16dp"
                android:textColor="#ffffff"
                android:text="Akash Bangad"
                android:textSize="14sp"
                android:textStyle="bold"


                />

    &lt;!&ndash;        android:background="#7f000000"
            android:singleLine="false"
            android:paddingLeft="5dp"
            android:paddingTop="5dp"
            android:paddingRight="15dp"
            android:paddingBottom="5dp"&ndash;&gt;

            <TextView
                android:id="@+id/email"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="inicio_texto_empresa"
                android:textColor="#ffffffff"
                android:layout_marginLeft="16dp"
               />
        </LinearLayout>

        <de.hdodenhof.circleimageview.CircleImageView
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:src="@drawable/barra_lateral_img_0_1"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="38dp"
            android:id="@+id/circleView"
            android:adjustViewBounds="false" />
    </RelativeLayout>-->

2 个答案:

答案 0 :(得分:0)

尝试将中间Linearlayout的权重设置为1,将其高度设置为0dp。因此,只有您的页眉和页脚具有固定的高度,而滚动视图将使用剩余的空间。

答案 1 :(得分:0)

据我所知,列表视图支持添加页脚视图,因此您可以使用listview对象添加自定义页脚R.layout.drawer_footer视图,如下代码所示

View footerView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.drawer_footer, expandableListView, false);
TextView footer = footerView.findViewById(R.id.id_footer_wta_version_information);
expandableListView.addFooterView(footerView);

在我的情况下,我使用expandableListView expandableListView与listView相同。希望这种方式对您有帮助