Android 回收视图下方的按钮
我试图将按钮放在Android 回收视图下方的按钮,android,xml,layout,Android,Xml,Layout,我试图将按钮放在回收视图的下方,这样当您在回收视图中向下滚动时,应该会有按钮(上一个/下一个) 下面给出了我正在尝试的XML。但是RecyclerView占据了所有空间 请注意,我已尝试放置layout\u height=0和layout\u weight=1,但仍不起作用 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
回收视图
的下方,这样当您在回收视图
中向下滚动时,应该会有按钮(上一个/下一个)
下面给出了我正在尝试的XML。但是RecyclerView
占据了所有空间
请注意,我已尝试放置layout\u height=0
和layout\u weight=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:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="0dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.app.home"
tools:showIn="@layout/app_bar_home">
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_homepost"
android:layout_width="match_parent"
android:layout_marginTop="5dp"
android:layout_height="0dp"
android:layout_weight="1">
</android.support.v7.widget.RecyclerView>
<LinearLayout
android:id="@+id/next_prev_button"
android:layout_below="@+id/rv_homepost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:gravity="center_vertical">
<Button
android:id="@+id/prev_button"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-4dp"
android:enabled="true"
android:text="Previous" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="@+id/next_button"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="-4dp"
android:enabled="true"
android:text="Next" />
</LinearLayout>
</LinearLayout>
试试这个。。。。有些更改可能对您有用 您忘记了线性布局的属性
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.app.home"
tools:showIn="@layout/app_bar_home">
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_homepost"
android:layout_width="match_parent"
android:layout_marginTop="5dp"
android:layout_height="0dp"
android:layout_weight="7">
</android.support.v7.widget.RecyclerView>
<LinearLayout
android:id="@+id/next_prev_button"
android:layout_below="@+id/rv_homepost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:layout_weight="1"
android:gravity="center_vertical">
<Button
android:id="@+id/prev_button"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_weight="1"
android:enabled="true"
android:text="Previous" />
<View
android:layout_width="1dp"
android:layout_height="match_parent" />
<Button
android:id="@+id/next_button"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="4dp"
android:layout_weight="1"
android:enabled="true"
android:text="Next" />
</LinearLayout>
</LinearLayout>
享受编码吧……你的根目录中缺少了android:orientation=“vertical”“LinearLayout”