Android 如果采用下面的属性布局_,如何向recyclerView添加按钮?
My activitymain.xml文件:Android 如果采用下面的属性布局_,如何向recyclerView添加按钮?,android,android-relativelayout,android-recyclerview,Android,Android Relativelayout,Android Recyclerview,My activitymain.xml文件: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <include android:id="@+id/app_bar" layout="@layout/toolbar"/> &l
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include android:id="@+id/app_bar" layout="@layout/toolbar"/>
<view
android:id="@+id/recycler_view"
android:layout_below="@id/app_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="android.support.v7.widget.RecyclerView"/>
</RelativeLayout>
因为我的main.java文件只包含Recyclerview而没有其他内容,所以我不能直接向其中添加两个按钮
我尝试在recyclerView中添加2个图像按钮
在AndroidStudio中,RecyclerView无法正确呈现自身-谷歌有一个问题
所以我看不出回收器视图和工具栏(app_栏)是如何相互独立的(我假设app_栏工具栏在recyclerview(layout_属性下))下面)
我想我应该完全改变应用程序的设计来完成它
MainActivity.java,它只有recyclerview和适配器,它将上下文发送到下一个SearchActivity:
public class MainActivity extends BaseActivity {
private static final String LOG_TAG = "mAIN ACTIVITY";
private List<Book> bookList = new ArrayList<>() ;
private RecyclerView recyclerView;
private BookRecyclerViewAdapter bookRecyclerViewAdapter;
private boolean FIRST_TIME_LAUNCH = false ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
bookRecyclerViewAdapter = new BookRecyclerViewAdapter(new ArrayList<Book>(), MainActivity.this);
recyclerView.setAdapter(bookRecyclerViewAdapter);
}
public类MainActivity扩展了BaseActivity{
私有静态最终字符串日志\u TAG=“主活动”;
private List bookList=new ArrayList();
私人回收站;
私人书籍回收服务适配器书籍回收服务适配器;
private boolean FIRST_TIME_LAUNCH=false;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView=(recyclerView)findViewById(R.id.recycler\u视图);
recyclerView.setLayoutManager(新的LinearLayoutManager(本));
BookRecycleServiceAdapter=new BookRecycleServiceAdapter(new ArrayList(),MainActivity.this);
setAdapter(BookRecycleServiceAdapter);
}
如果我尝试添加按钮,它位于左上角:
如果您想在列表向下滚动后在列表末尾显示该按钮,请查看问题 如果您希望列表下方的按钮始终可见,请执行以下操作: 您在按钮和
工具栏之间“挤压”了RecyclerView
,使其在下方有布局,在上方有布局属性:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include android:id="@+id/app_bar" layout="@layout/toolbar"/>
<Button
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<view
android:id="@+id/recycler_view"
android:layout_below="@id/app_bar"
android:layout_above="@id/button"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="android.support.v7.widget.RecyclerView"/>
</RelativeLayout>
试试这个:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include android:id="@+id/app_bar" layout="@layout/toolbar"/>
<view
android:id="@+id/recycler_view"
android:layout_below="@id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
class="android.support.v7.widget.RecyclerView"/>
<Button
android:id="@+id/button"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_below="@id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
希望这有帮助!我不太明白你想要按钮的位置…在Recyclerview下面?@Ascorbin,是的,在Recyclerer下面,这样我向下滚动按钮后,就可以加载下一页的书了…如果你把按钮放在Recyclerview
下面会有什么问题?@Xcihnegn,我已经在app\u barLook上使用下面的布局了用修改后的布局回答问题,但为什么看起来不好?如果我只在列表末尾看到按钮?忘记这一点。看看我链接的问题,如果你希望你的按钮出现在列表末尾,或者使用我的布局,如果你希望按钮始终可见。好的,谢谢-链接中的答案假设我将使用ListView,这意味着s我必须重做我的主要活动…我完成了您的解决方案,按钮仍停留在那里,但它很难看!))我明白了。您仍然可以在适配器中使用自己的“底部页脚视图”创建自己的“底部页脚视图”。请参见