将Linearlayout放在ListView下

时间:2017-03-31 09:08:04

标签: android android-layout listview

我面临的问题是在listview下放置一个linearlayout,如图片链接所示:

enter image description here

我想要使用添加图标和文字进行布局:"添加新成员"显示在列表视图下方。我究竟做错了什么?请帮我解决问题。非常感谢你。

这是布局的xml文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.thomasbrown.myapplication.MemberActivity"
android:background="@android:color/white">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/groupID"
    android:textSize="20sp"
    android:layout_marginBottom="15dp" />

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

    <ListView
        android:id="@+id/ListView1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="@android:color/white"
        android:layout_weight="1" />

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

        <ImageView
            app:srcCompat="@drawable/add"
            android:id="@+id/imageView2"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_width="80dp"
            android:layout_height="60dp"
            android:layout_weight="1" />

        <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/addMember"
                android:text="Add New Members"
                android:textSize="18sp"
                android:textColor="@android:color/holo_red_dark"
            android:layout_weight="1"
            android:layout_gravity="center_vertical" />
    </LinearLayout>

</LinearLayout>


<Button
    android:text="Leave this group"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/leaveGroupButton"
    android:background="@color/colorPrimary"
    android:layout_gravity="bottom|end" />

</LinearLayout>

6 个答案:

答案 0 :(得分:0)

 <ScrollView ..

   <RelativeLayout.. 

      <LinearLayout // vertical orientation

          <ListView ../>

          <LinearLayout  // your linear layout
              layout_below="@+id/listviewid"
      </LinearLayout>

   </RelativeLayout>

 </ScrollView>

尝试此视图层次结构。

答案 1 :(得分:0)

问题是android:layout_weight="1"上有ListView这会使其扩展为完整版并且不会为LinearLayout

提供空间

答案 2 :(得分:0)

您必须在列表视图项目中进行更改,请检查此项。

将以下行添加到Adapter get view方法中:

    @Override
        public View getView(int i, View view, ViewGroup viewGroup) {

            view = LayoutInflater.from(TestListActivity.this).inflate(R.layout.dummy, viewGroup,false);

                    LinearLayout layout =  (LinearLayout)view.findViewById(R.id.add_bottom_ll);
                    if(i==getCount()-1){
                        layout.setVisibility(View.VISIBLE);
                    }else{
                        layout.setVisibility(View.GONE);
                    }
            return view;

        }

列表视图项目视图xml

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp">

            <ImageView
                android:id="@+id/profile"
                android:layout_width="72dp"
                android:layout_height="72dp"
                android:src="@drawable/arrow" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/profile"
                android:layout_alignParentTop="true"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@id/profile"
                android:gravity="center_vertical"
                android:text="user Name"
                android:textSize="18sp" />
        </RelativeLayout>

        <LinearLayout
            android:id="@+id/add_bottom_ll"
            android:layout_width="363dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="80dp"
                android:layout_height="60dp"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_weight="1"
                android:src="@drawable/index" />

            <TextView
                android:id="@+id/addMember"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"
                android:text="Add New Members"
                android:textColor="@android:color/holo_red_dark"
                android:textSize="18sp" />
        </LinearLayout>

    </LinearLayout>

查看(活动或片段)xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context="com.thomasbrown.myapplication.MemberActivity"
        android:background="@android:color/white">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/groupID"
            android:textSize="20sp"
            android:layout_marginBottom="15dp" />

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

            <ListView
                android:id="@+id/ListView1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:background="@android:color/white"
                />

        </LinearLayout>


        <Button
            android:text="Leave this group"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/leaveGroupButton"
            android:background="@color/colorPrimary"
            android:layout_gravity="bottom|end" />

    </LinearLayout>

答案 3 :(得分:0)

尝试RelativeLayout并使用android:layout_above,如下所示:

    <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <ListView
                android:id="@+id/your_listview"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_above="@+id/your_layout_with_buttons" />

            <LinearLayout
                android:layout_alignParentBottom="true"
                android:id="@+id/your_layout_with_buttons"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

//your buttons come here

            </LinearLayout>
        </RelativeLayout>

答案 4 :(得分:0)

  1. 如果您想将set FLASK_APP=contact.py按钮"Add New Members"scrollable设置为relative高度,请使用ListView作为NestedScrollView和{ListView的容器{1}}自定义按钮"Add New Members"
  2. 以下是完整的XML代码:

    LinearLayout

    <强>输出:

    enter image description here

    1. 如果您想将<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:background="@android:color/white"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/groupID" android:textSize="20sp" android:layout_marginBottom="15dp" /> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ListView android:id="@+id/ListView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white" /> <LinearLayout android:id="@+id/layout_add_new_member" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView app:srcCompat="@drawable/add" android:id="@+id/imageView2" android:layout_marginLeft="16dp" android:layout_width="80dp" android:layout_height="60dp" android:layout_weight="1" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:id="@+id/addMember" android:text="Add New Members" android:textSize="18sp" android:textColor="@android:color/holo_red_dark" android:layout_weight="1" android:layout_gravity="center_vertical" /> </LinearLayout> </LinearLayout> </android.support.v4.widget.NestedScrollView> <Button android:text="Leave this group" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/leaveGroupButton" android:background="@color/colorPrimary" android:layout_gravity="bottom|end" /> </LinearLayout> 按钮固定在底部,请使用"Add New Members"作为RelativeLayoutListView自定义按钮"Add New Members"的容器。
    2. 以下是完整的XML代码:

      LinearLayout

      <强>输出:

      OUTPUT:

      希望这会有所帮助〜

答案 5 :(得分:-1)

我没有尝试,但你试试这个让我知道:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@android:color/white">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/groupID"
    android:textSize="20sp"
    android:layout_marginBottom="15dp" />

<Button
    android:text="Leave this group"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/leaveGroupButton"
    android:background="@color/colorPrimary"
    android:layout_alignParentBottom="true" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/leaveGroupButton"
    android:layout_below="@id/groupID">

    <ListView
        android:id="@+id/ListView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:background="@android:color/white" />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/ListView1">

        <ImageView
            app:srcCompat="@drawable/add"
            android:id="@+id/imageView2"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_width="80dp"
            android:layout_height="60dp"
            android:layout_weight="1" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/addMember"
            android:text="Add New Members"
            android:textSize="18sp"
            android:textColor="@android:color/holo_red_dark"
            android:layout_weight="1"
            android:layout_gravity="center_vertical" />
    </LinearLayout>
</RelativeLayout>