I'm facing problem to put a linearlayout under the listview like what is shown in this image link:
I want the layout with the Add icon and text:"Add New Members" to be displayed under the listview. What am I doing wrong? Pls help me to solve the problem. Thank you very much.
This is the xml file for the layout
<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>
Problem is you have android:layout_weight="1" on your ListView which will make it expand to full and give no space to your LinearLayout
If you want to make "Add New Members" button scrollable and relative to ListView height, use NestedScrollView as a container of ListView and "Add New Members" custom button LinearLayout.
Here is full XML code:
<?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>
OUTPUT:
If you want to make "Add New Members" button fixed at bottom, use RelativeLayout as a container of ListView and "Add New Members" custom button LinearLayout.
Here is full XML code:
<?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" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<LinearLayout
android:id="#+id/layout_add_new_member"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<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>
<ListView
android:id="#+id/ListView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="#id/layout_add_new_member"
android:background="#android:color/white" />
</RelativeLayout>
<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>
OUTPUT:
Hope this will help~
<ScrollView ..
<RelativeLayout..
<LinearLayout // vertical orientation
<ListView ../>
<LinearLayout // your linear layout
layout_below="#+id/listviewid"
</LinearLayout>
</RelativeLayout>
</ScrollView>
Try this view hierarchy.
Try RelativeLayout and use android:layout_above as shown below:
<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>
You have to make changes in you list view item for this, check this.
Add below lines into Adapter get view method:
#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;
}
List view Item 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>
View(Activity or Fragment) 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>
I haven't tried but you try this and let me know:
<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>
Related
I am building an app that needs a mapview and a textview to enable a place/location picker. It is to be like "uber" where the mapview fills the whole screen and then the editext views for choosing a location are superimposed on top of the map view. The issue is that my design xml file places the textviews "behind" the mapview so that they are covered by the map and not visible. How can i do it that they appear over the mapview ; while the mapview still covers 100% of the screen height?. My xml file is shown below:
<?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"
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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
>
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textColor="#color/colorPrimary"
android:text="Pickup Location"
android:id="#+id/pickup"
android:textSize="15sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textColor="#color/colorPrimary"
android:text="Drop Location"
android:id="#+id/drop"
android:textSize="15sp"
android:layout_alignParentLeft="true"
android:layout_below="#id/pickup"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ride_start"
android:layout_margin="10dp"
android:textSize="15sp"
android:visibility="gone"
android:textColor="#color/colorPrimary"
android:layout_below="#+id/drop"
android:text="Start"/>
</LinearLayout>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="MainActivity"
/>
<LinearLayout
android:layout_width="match_parent"
android:id="#+id/info"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#F8CA2B"
android:gravity="center_vertical" >
<TextView
android:id="#+id/totaldistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:textColor="#000" />
<View
android:layout_width="2dp"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:background="#fff" />
<TextView
android:id="#+id/cost"
android:padding="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000" />
</LinearLayout>
set map fragement first then overlay of relative layout might be helpful.
<?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"
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"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="MainActivity"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textColor="#color/colorPrimary"
android:text="Pickup Location"
android:id="#+id/pickup"
android:textSize="15sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textColor="#color/colorPrimary"
android:text="Drop Location"
android:id="#+id/drop"
android:textSize="15sp"
android:layout_alignParentLeft="true"
android:layout_below="#id/pickup"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ride_start"
android:layout_margin="10dp"
android:textSize="15sp"
android:visibility="gone"
android:textColor="#color/colorPrimary"
android:layout_below="#+id/drop"
android:text="Start"/>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:id="#+id/info"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#F8CA2B"
android:gravity="center_vertical" >
<TextView
android:id="#+id/totaldistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:textColor="#000" />
<View
android:layout_width="2dp"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:background="#fff" />
<TextView
android:id="#+id/cost"
android:padding="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000" />
</LinearLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:circular="http://schemas.android.com/tools"
android:id="#+id/content_frame"
xmlns:app="http://schemas.android.com/apk/res-auto">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/content_frame_child">
<!--Your map fragment-->
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="MainActivity"/>
<!--Your map fragment ends-->
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:id="#+id/info"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#F8CA2B"
android:gravity="center_vertical" >
<TextView
android:id="#+id/totaldistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:textColor="#000" />
<View
android:layout_width="2dp"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:background="#fff" />
<TextView
android:id="#+id/cost"
android:padding="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000" />
</LinearLayout>
</FrameLayout>
Use frame layout for overlay
Use Following code
<?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"
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"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:orientation="vertical">
<TextView
android:id="#+id/pickup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Pickup Location"
android:textColor="#color/colorPrimary"
android:textSize="15sp" />
<TextView
android:id="#+id/drop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#id/pickup"
android:layout_margin="10dp"
android:text="Drop Location"
android:textColor="#color/colorPrimary"
android:textSize="15sp" />
<TextView
android:id="#+id/ride_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/drop"
android:layout_margin="10dp"
android:text="Start"
android:textColor="#color/colorPrimary"
android:textSize="15sp"
android:visibility="gone" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="MainActivity"
/>
<LinearLayout
android:id="#+id/info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/map"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:background="#F8CA2B"
android:gravity="center_vertical">
<TextView
android:id="#+id/totaldistance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:textColor="#000" />
<View
android:layout_width="2dp"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:background="#fff" />
<TextView
android:id="#+id/cost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:textColor="#000" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Iam developing an android application where i need scrollable view for particular child layout which is scrollable if it possible please suggest below are pictorial explanation.
below are code for explanation.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="android.xyz.com.xyz.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:orientation="vertical">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical"
android:scrollbars="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/ntitled" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/ic_tp"
/>
</LinearLayout>
</LinearLayout>
Edit1: For the clarification.
You can do that adding code like this in your .xml layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/nreg" />
<EditText
android:id="#+id/txtReg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
android:ems="10"
android:inputType="number">
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/val" />
<EditText
android:id="#+id/txtVal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="text"/>
</LinearLayout>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btnInsertar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ins" />
<Button
android:id="#+id/btnActualizar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/act" />
<Button
android:id="#+id/btnEliminar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/elim" />
<Button
android:id="#+id/btnConsultar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cons" />
<Button
android:id="#+id/gaf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cons" />
<Button
android:id="#+id/asd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/cons" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
I read this: How to align linearlayout to vertical center?
But it didn't help me
Basically I am trying to center 2 ImageButtons in the middle of my screen. The two buttons are horizontally orientated in a linearLayout.
I tried to use a relativeLayout with vertical orientation to center the two imagebuttons in the center in the vertical direction but that doesnt seem to do the job.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="#+id/activity_main"
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="#color/white"
tools:context="com.example.max.testcase.MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="loadSomething"
android:padding="5sp"
android:layout_marginTop="5sp"
android:layout_marginBottom="5sp"
android:textAlignment="center"
android:text="Click here to load the site"
android:textColor="#color/white"
android:textSize="16sp"
android:background="#color/blue"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<ImageButton
android:id="#+id/icon1"
android:onClick="method1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="100sp"
android:padding="20dp"
android:paddingTop="50dp"
android:adjustViewBounds="true"
android:layout_gravity="left"
android:gravity="center_horizontal"
android:scaleType = "fitCenter"
android:maxWidth="350dp"
android:maxHeight="350dp"
android:background="#color/white"
android:src="#drawable/icon1" />
<ImageButton
android:id="#+id/icon2"
android:onClick="method2"
android:layout_width="0dp"
android:layout_weight= "1"
android:layout_height="wrap_content"
android:layout_marginTop="100sp"
android:padding="20dp"
android:paddingTop="50dp"
android:layout_gravity="right"
android:gravity="center_horizontal"
android:adjustViewBounds="true"
android:maxWidth="350dp"
android:maxHeight="350dp"
android:scaleType="fitCenter"
android:background="#color/white"
android:src="#drawable/icon2"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
The two buttons keep sticking to the top button bar
Put
android:layout_height="match_parent"
to the RelativeLayout,
and replace android:layout_gravity="center" with
android:layout_centerInParent="true"
in its child LinearLayout
Make it like -
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="#+id/activity_main"
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="#color/white"
tools:context="com.example.max.testcase.MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="loadSomething"
android:padding="5sp"
android:layout_marginTop="5sp"
android:layout_marginBottom="5sp"
android:textAlignment="center"
android:text="Click here to load the site"
android:textColor="#color/white"
android:textSize="16sp"
android:background="#color/blue"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="center_vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerInParent="true">
<ImageButton
android:id="#+id/icon1"
android:onClick="method1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="100sp"
android:padding="20dp"
android:paddingTop="50dp"
android:adjustViewBounds="true"
android:layout_gravity="left"
android:gravity="center_horizontal"
android:scaleType = "fitCenter"
android:maxWidth="350dp"
android:maxHeight="350dp"
android:background="#color/white"
android:src="#drawable/icon1" />
<ImageButton
android:id="#+id/icon2"
android:onClick="method2"
android:layout_width="0dp"
android:layout_weight= "1"
android:layout_height="wrap_content"
android:layout_marginTop="100sp"
android:padding="20dp"
android:paddingTop="50dp"
android:layout_gravity="right"
android:gravity="center_horizontal"
android:adjustViewBounds="true"
android:maxWidth="350dp"
android:maxHeight="350dp"
android:scaleType="fitCenter"
android:background="#color/white"
android:src="#drawable/icon2"
/>
</LinearLayout>
</RelativeLayout> </LinearLayout>
your question seems bit unclear but hope this tip will help you
android:layout_gravity
android:layout_gravity is used to set the position of an element in its parent (e.g. a child View inside a Layout).
Supported by LinearLayout and FrameLayout
android:gravity
android:gravity is used to set the position of content inside an element (e.g. a text inside a TextView).
to get and idea copy this XML and understand how it works
<?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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_gravity="left"
android:gravity="center_vertical">
<TextView
android:layout_width="#dimen/fixed"
android:layout_height="wrap_content"
android:text="#string/first"
android:background="#color/colorPrimary"
android:gravity="left"/>
<TextView
android:layout_width="#dimen/fixed"
android:layout_height="wrap_content"
android:text="#string/second"
android:background="#color/colorPrimary"
android:gravity="center"/>
<TextView
android:layout_width="#dimen/fixed"
android:layout_height="wrap_content"
android:text="#string/third"
android:background="#color/colorPrimary"
android:gravity="right"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_gravity="center"
android:gravity="center_vertical">
<TextView
android:layout_width="#dimen/fixed"
android:layout_height="wrap_content"
android:text="#string/first"
android:background="#color/colorAccent"
android:gravity="left"/>
<TextView
android:layout_width="#dimen/fixed"
android:layout_height="wrap_content"
android:text="#string/second"
android:background="#color/colorAccent"
android:gravity="center"/>
<TextView
android:layout_width="#dimen/fixed"
android:layout_height="wrap_content"
android:text="#string/third"
android:background="#color/colorAccent"
android:gravity="right"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_gravity="right"
android:gravity="center_vertical">
<TextView
android:layout_width="#dimen/fixed"
android:layout_height="wrap_content"
android:text="#string/first"
android:background="#color/colorPrimaryDark"
android:gravity="left"/>
<TextView
android:layout_width="#dimen/fixed"
android:layout_height="wrap_content"
android:text="#string/second"
android:background="#color/colorPrimaryDark"
android:gravity="center"/>
<TextView
android:layout_width="#dimen/fixed"
android:layout_height="wrap_content"
android:text="#string/third"
android:background="#color/colorPrimaryDark"
android:gravity="right"/>
</LinearLayout>
</LinearLayout>
Make sure all parent layouts of Button's have set android:layout_height="match_parent"
Then apply android:layout_centerVertical="true" to the RelativeLayout.
Try this way it will work
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="#+id/activity_main"
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"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="loadSomething"
android:padding="5sp"
android:layout_marginTop="5sp"
android:layout_marginBottom="5sp"
android:textAlignment="center"
android:text="Click here to load the site"
android:textColor="#ffffff"
android:textSize="16sp"
android:background="#ff00"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="center_vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerVertical="true"
android:layout_gravity="center">
<ImageButton
android:id="#+id/icon1"
android:onClick="method1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="100sp"
android:padding="20dp"
android:paddingTop="50dp"
android:adjustViewBounds="true"
android:layout_gravity="left"
android:gravity="center_horizontal"
android:scaleType = "fitCenter"
android:maxWidth="350dp"
android:maxHeight="350dp"
android:background="#ffffff"
android:src="#mipmap/ic_launcher" />
<ImageButton
android:id="#+id/icon2"
android:onClick="method2"
android:layout_width="0dp"
android:layout_weight= "1"
android:layout_height="wrap_content"
android:layout_marginTop="100sp"
android:padding="20dp"
android:paddingTop="50dp"
android:layout_gravity="right"
android:gravity="center_horizontal"
android:adjustViewBounds="true"
android:maxWidth="350dp"
android:maxHeight="350dp"
android:scaleType="fitCenter"
android:background="#ffffff"
android:src="#mipmap/ic_launcher"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Change your layout like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="#+id/activity_main"
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="#color/white"
tools:context="com.example.max.testcase.MainActivity">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="loadSomething"
android:padding="5sp"
android:layout_marginTop="5sp"
android:layout_marginBottom="5sp"
android:textAlignment="center"
android:text="Click here to load the site"
android:textColor="#color/white"
android:textSize="16sp"
android:background="#color/blue"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
android:layout_centerVertical="true"
android:layout_alignParentStart="true">
<ImageButton
android:id="#+id/icon1"
android:onClick="method1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="100sp"
android:padding="20dp"
android:paddingTop="50dp"
android:adjustViewBounds="true"
android:layout_gravity="left"
android:gravity="center_horizontal"
android:scaleType = "fitCenter"
android:maxWidth="350dp"
android:maxHeight="350dp"
android:background="#color/white"
android:src="#drawable/icon1" />
<ImageButton
android:id="#+id/icon2"
android:onClick="method2"
android:layout_width="0dp"
android:layout_weight= "1"
android:layout_height="wrap_content"
android:layout_marginTop="100sp"
android:padding="20dp"
android:paddingTop="50dp"
android:layout_gravity="right"
android:gravity="center_horizontal"
android:adjustViewBounds="true"
android:maxWidth="350dp"
android:maxHeight="350dp"
android:scaleType="fitCenter"
android:background="#color/white"
android:src="#drawable/icon2"
/>
</LinearLayout>
</RelativeLayout>
add layout_gravity and gravity attribute in root linear layout with value center vertical it will make all his child align in center vertical.
Note: make child height wrap_content, to achieve this. if your child height is match_parent than this will not work.
A simple layout design for center two image button
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="loadSomething"
android:layout_margin="20dp"
android:textAlignment="center"
android:text="Click here to load the site"
android:textColor="#color/WhiteSmoke"
android:textSize="16sp"
android:background="#color/Blue"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
<ImageButton
android:id="#+id/icon1"
android:onClick="method1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:padding="20dp"
android:adjustViewBounds="true"
android:scaleType = "fitCenter"
android:maxWidth="350dp"
android:maxHeight="350dp"
android:background="#color/WhiteSmoke"
android:src="#mipmap/minus_icon" />
<ImageButton
android:id="#+id/icon2"
android:onClick="method2"
android:layout_width="0dp"
android:layout_weight= "1"
android:layout_height="wrap_content"
android:padding="20dp"
android:adjustViewBounds="true"
android:maxWidth="350dp"
android:maxHeight="350dp"
android:scaleType="fitCenter"
android:background="#color/WhiteSmoke"
android:src="#mipmap/plus_icon"
/>
</LinearLayout>
</RelativeLayout>
My activity looks like this:
I use this XML :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<SearchView
android:layout_width="0px"
android:layout_height="wrap_content"
android:background="#5b74a8"
android:padding="4dp"
android:id="#+id/searchView"
android:singleLine="true"
android:layout_gravity="right"
android:layout_weight="7">
</SearchView>
<ImageButton
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:id="#+id/settingsButton"
android:src="#drawable/settingsicon"
android:background="#drawable/ambuttonstatessettings"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:onClick="settingsPopUp"
/>
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/contacts_list"></ListView>
</LinearLayout>
But I want it to look like this, with a checkbox above the keyboard. Or if the keyboard is not there, the checkbox should be at the bottom :
Any idea how I can do this ? I tried this code, which is the closest I've come (basically, making a new linear layout at the bottom) but I can't get it right. And can't figure out why.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<SearchView
android:layout_width="0px"
android:layout_height="wrap_content"
android:background="#5b74a8"
android:padding="4dp"
android:id="#+id/searchView"
android:singleLine="true"
android:layout_gravity="right"
android:layout_weight="7">
</SearchView>
<!--android:drawableLeft="#android:drawable/ic_menu_search"-->
<!--android:queryHint="howdy"-->
<ImageButton
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:id="#+id/settingsButton"
android:src="#drawable/settingsicon"
android:background="#drawable/ambuttonstatessettings"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:onClick="settingsPopUp"
/>
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/contacts_list"></ListView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal" >
<CheckBox
android:layout_height="match_parent"
android:layout_width="0dp"
android:background="#ffa500"
android:text="New CheckBox"
android:id="#+id/checkBox"
android:layout_weight="1"
/>
</LinearLayout>
</LinearLayout>
try this:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<SearchView
android:layout_width="0px"
android:layout_height="wrap_content"
android:background="#5b74a8"
android:padding="4dp"
android:id="#+id/searchView"
android:singleLine="true"
android:layout_gravity="right"
android:layout_weight="7"/>
<!--android:drawableLeft="#android:drawable/ic_menu_search"-->
<!--android:queryHint="howdy"-->
<ImageButton
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:id="#+id/settingsButton"
android:background="#787878"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:onClick="settingsPopUp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100">
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="80"
android:id="#+id/contacts_list"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_weight="20"
android:orientation="horizontal" >
<CheckBox
android:layout_height="match_parent"
android:layout_width="0dp"
android:background="#ffa500"
android:text="New CheckBox"
android:id="#+id/checkBox"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
this is the solution.
I am trying to put buttons below a RecyclerView, in such a way that when you scroll all the way down in the RecyclerView, there should be the button (Previous/Next)
The XML I am trying is given below. But the RecyclerView takes all the space.
Please note I have tried putting layout_height=0 and layout_weight=1, but it still is not working.
<?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>
just try this .... there is some changes may be useful for you.
You forgot android:orientation="vertical" property for linear layout..
<?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>
enjoy coding......