如何在 Scrollable Activity 中的 ListView 下方放置一个 Button?
How to Place a Button below a ListView in a Scrollable Activity?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".list1">
<ImageView
android:id="@+id/sinb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/left"
android:padding="10dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
/>
<ListView
android:layout_below="@id/sinb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView1"
android:layout_marginTop="30dp"
android:layout_centerHorizontal="true"
android:choiceMode="multipleChoice" />
<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/listView1"
android:text="submit"/>
</RelativeLayout>
我已将它们放在相对布局中。我已尝试使用 ScrollView,但它不起作用。我想要的是提交按钮应显示在列表视图下方,当列表增长并离开屏幕时,activity 变为可滚动按钮应显示在列表视图末尾下方。
对于您想要的行为,如果您使用 RecyclerView 而不是 ListView 并将其放在 NestedScrollView 中,然后在 RecyclerView 上启用 nestedScrolling 属性,会更好。这样,您的 RecyclerView 将表现得像一个长列表,它下面的所有视图只有在列表用完后才可见。
检查 answers in this link 看看其他人是如何实现的。
所以为此你必须把你的列表和按钮放在 NestedScrollView
里面,但是 Nestedscrollview
只支持一个 child 所以首先你必须把你的 List
and button
inside a Layout 然后把layout放在NestedScrollView
, 你可以参考下面的代码:
<?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="match_parent"
xmlns:tools="http://schemas.android.com/tools">
<ImageView
android:id="@+id/sinb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:padding="10dp"
android:src="@drawable/left" />
<android.support.v4.widget.NestedScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="@id/sinb">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
tools:listitem="@layout/item_view_note"
android:choiceMode="multipleChoice" />
<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/listView1"
android:text="submit" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</RelativeLayout>
添加 ScrollView/NestedScrollView 作为父布局并在滚动视图(ListView 和 Button )中添加视图
试试这个代码:
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".list1">
<ImageView
android:id="@+id/sinb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/left"
android:padding="10dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
/>
<android.support.v4.widget.NestedScrollView
android:id="@+id/navigation_nested"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_below="@+id/sinb"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/margin_15">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView1"
android:layout_marginTop="30dp"
android:layout_centerHorizontal="true"
android:choiceMode="multipleChoice" />
<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="submit"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</RelativeLayout >
固定listView的高度,然后把button放在下面。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".list1">
<ImageView
android:id="@+id/sinb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/left"
android:padding="10dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
/>
<ListView
android:layout_below="@id/sinb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView1"
android:layout_marginTop="30dp"
android:layout_centerHorizontal="true"
android:choiceMode="multipleChoice" />
<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/listView1"
android:text="submit"/>
</RelativeLayout>
我已将它们放在相对布局中。我已尝试使用 ScrollView,但它不起作用。我想要的是提交按钮应显示在列表视图下方,当列表增长并离开屏幕时,activity 变为可滚动按钮应显示在列表视图末尾下方。
对于您想要的行为,如果您使用 RecyclerView 而不是 ListView 并将其放在 NestedScrollView 中,然后在 RecyclerView 上启用 nestedScrolling 属性,会更好。这样,您的 RecyclerView 将表现得像一个长列表,它下面的所有视图只有在列表用完后才可见。 检查 answers in this link 看看其他人是如何实现的。
所以为此你必须把你的列表和按钮放在 NestedScrollView
里面,但是 Nestedscrollview
只支持一个 child 所以首先你必须把你的 List
and button
inside a Layout 然后把layout放在NestedScrollView
, 你可以参考下面的代码:
<?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="match_parent"
xmlns:tools="http://schemas.android.com/tools">
<ImageView
android:id="@+id/sinb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:padding="10dp"
android:src="@drawable/left" />
<android.support.v4.widget.NestedScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="@id/sinb">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="30dp"
tools:listitem="@layout/item_view_note"
android:choiceMode="multipleChoice" />
<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/listView1"
android:text="submit" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</RelativeLayout>
添加 ScrollView/NestedScrollView 作为父布局并在滚动视图(ListView 和 Button )中添加视图
试试这个代码:
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".list1">
<ImageView
android:id="@+id/sinb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/left"
android:padding="10dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
/>
<android.support.v4.widget.NestedScrollView
android:id="@+id/navigation_nested"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_below="@+id/sinb"
android:overScrollMode="never">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/margin_15">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/listView1"
android:layout_marginTop="30dp"
android:layout_centerHorizontal="true"
android:choiceMode="multipleChoice" />
<Button
android:id="@+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="submit"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</RelativeLayout >
固定listView的高度,然后把button放在下面。