RecycleView Header all In One (header + listview + footer)

荒凉一梦 提交于 2019-12-12 05:54:07

问题


I have problem with my Header I want include all, because I want a footer static.

I try show in :

  • screens 3.7 show correctly

  • Screen > 4.0 show incorrectly

My adapter (Only put header full with footer)

   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


        }

My 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>-->

回答1:


Try to set the weight of the middle Linearlayout to 1 and its height to 0dp. So only your header and your footer have a fixed height and the scrollview will use the remaining space.



来源:https://stackoverflow.com/questions/32460312/recycleview-header-all-in-one-header-listview-footer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!