0

My activitymain.xml file:

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

Because my main.java file only contains Recyclerview and nothing else, i can't directly add 2 buttons into it.

I tried to add 2 imageButtons in the the recyclerView.

RecyclerView does not properly render itself in AndroidStudio - there is an issue from google.

So i can't see how exactly recycler view and toolbar(app_bar) stand to each other(I assume app_bar toolbar is below recyclerview(layout_below attribute) )

I suspect i should totally change the design of the app to finish it.

MainActivity.java, it only has recyclerview and adapter to it, it sends context into next 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);

        }

If i try to add button it stands in upper left corner:

kk

ERJAN
  • 23,696
  • 23
  • 72
  • 146

2 Answers2

1

If you want the button to appear at the end of your list after the list has been scrolled down have a look at this question.

If you want the button below your list and be always visible, this is how you do it: You 'squeeze in' the RecyclerView between the Button and the Toolbar giving it a layout_below and layout_above attribute:

<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>
Community
  • 1
  • 1
fweigl
  • 21,278
  • 20
  • 114
  • 205
  • but why is it not look good? if i see the button only at the end of the list? – ERJAN Mar 25 '15 at 17:29
  • 1
    Forget about that. Have a look at the question I linked if you want you button appear at the end of the list or use my layout if you want the button always visible. – fweigl Mar 25 '15 at 17:30
  • alright, thanks - the answer in the link assumes i will use ListView, which means I have to redo my main activity... i did your solution and the button stays there, but it s ugly! ))) – ERJAN Mar 25 '15 at 18:07
  • I see. You can still create your own 'bottom footer view' with own your own within your adapter. See http://stackoverflow.com/questions/26530685/is-there-an-addheaderview-equivalent-for-recyclerview – fweigl Mar 25 '15 at 18:11
1

Try this:

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

Hope this help!

Xcihnegn
  • 11,579
  • 10
  • 33
  • 33