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......
Related
I want my RelativeLayout to be scrollable in Landscape.
I tried doing this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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"
tools:context=".RelativeActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/headline_icon" />
<TextView
android:id="#+id/relative_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/layout_uebersicht" />
<LinearLayout
android:id="#+id/ll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/relative_textview"
android:layout_centerHorizontal="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/relativebutton_linearlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onButtonLinearLayoutClick"
android:text="#string/linear_layout" />
<Button
android:id="#+id/relativebutton_tablelayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onButtonTableLayoutClick"
android:text="#string/table_layout" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/relativebutton_framelayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onButtonFrameLayoutClick"
android:text="#string/frame_layout" />
<Button
android:id="#+id/relativebutton_gridlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onButtonGridLayoutClick"
android:text="#string/grid_layout" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:src="#drawable/baseline_icon" />
</RelativeLayout>
</ScrollView>
But it messes everything up like this
I have also tried putting a simple LinearLayout between the ScrollView and the RelativeLayout and switching all the layout_height and width values around. None of this will work.
The android:fillViewport="true" does not work either.
My code looks like this without the ScrollView:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".RelativeActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/headline_icon" />
<TextView
android:id="#+id/relative_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/layout_uebersicht" />
<LinearLayout
android:id="#+id/ll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/relative_textview"
android:layout_centerHorizontal="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/relativebutton_linearlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onButtonLinearLayoutClick"
android:text="#string/linear_layout" />
<Button
android:id="#+id/relativebutton_tablelayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onButtonTableLayoutClick"
android:text="#string/table_layout" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/relativebutton_framelayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onButtonFrameLayoutClick"
android:text="#string/frame_layout" />
<Button
android:id="#+id/relativebutton_gridlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onButtonGridLayoutClick"
android:text="#string/grid_layout" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:src="#drawable/baseline_icon" />
</RelativeLayout>
Create a HorizontalScrollView and inside it , design your RelativeLayout like this :
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/headline_icon" />
<TextView
android:id="#+id/relative_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/layout_uebersicht" />
<LinearLayout
android:id="#+id/ll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/relative_textview"
android:layout_centerHorizontal="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/relativebutton_linearlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onButtonLinearLayoutClick"
android:text="#string/linear_layout" />
<Button
android:id="#+id/relativebutton_tablelayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onButtonTableLayoutClick"
android:text="#string/table_layout" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/relativebutton_framelayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onButtonFrameLayoutClick"
android:text="#string/frame_layout" />
<Button
android:id="#+id/relativebutton_gridlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onButtonGridLayoutClick"
android:text="#string/grid_layout" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:src="#drawable/baseline_icon" />
</RelativeLayout>
</HorizontalScrollView>
Consider that your RelativeLayout width should be wrap_content
The below is my xml file in which i want a linearlayout to be in bottom i.e. layout gravity bottom. But it is not working.
Even after looking all solutions given for this type of problem, i am not able to solve it. Please Help
<?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">
<include layout="#layout/toolbar_layout" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewCart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" //----> not working
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/total"
android:textStyle="bold" />
<TextView
android:id="#+id/textViewTotalPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="$23.00" />
</LinearLayout>
<Button
android:id="#+id/buttonCheckout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="20dp"
android:layout_weight="1"
android:background="#color/colorPrimary"
android:drawableEnd="#drawable/ic_arrow_forward"
android:paddingEnd="15dp"
android:text="#string/checkout"
android:textColor="#color/white" />
</LinearLayout>
This is the way i want.
Try this
<?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">
<include layout="#layout/toolbar_layout" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewCart"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="total"
android:textStyle="bold" />
<TextView
android:id="#+id/textViewTotalPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="$23.00" />
</LinearLayout>
<Button
android:id="#+id/buttonCheckout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="20dp"
android:background="#color/colorPrimary"
android:drawableEnd="#drawable/ic_arrow_forward"
android:paddingEnd="15dp"
android:text="#string/checkout"
android:textColor="#color/white" />
</LinearLayout>
</LinearLayout>
Put Space layout between RecyclerView and LinearLayout
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
or use RelativeLayout instead of your main LinearLayout
Try this code.. and change this
<?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">
<include layout="#layout/toolbar_layout" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerViewCart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="tees"
android:textStyle="bold" />
<TextView
android:id="#+id/textViewTotalPrice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="$23.00" />
</LinearLayout>
<Button
android:id="#+id/buttonCheckout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="20dp"
android:layout_weight="1"
android:background="#color/colorPrimary"
android:paddingEnd="15dp"
android:text="Hello" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
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>
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 want to achieve the following layout.
How do I make the button 0 equal to rest of the buttons. Please note that I have used layout_weight = "1" so that all of the rest of the buttons are of equal length while matching the parent. Since, I have created button 0 on a different layout so I can't seem to make it of equal length with other buttons.
Here's my code so far
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/seven"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
<Button
android:id="#+id/eight"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
<Button
android:id="#+id/nine"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/zero"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Take the zero button out of the LinearLayout, I assume there is another layout all this are defined in, like a relative layout? and try something to this effect.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout">
<Button
android:id="#+id/seven"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
<Button
android:id="#+id/eight"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
<Button
android:id="#+id/nine"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:id="#+id/zero"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout"
android:layout_marginTop="98dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
Take the last button in another linearlayout and further add linearlayout in it with weight, try this code....
<?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: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">
<Button
android:id="#+id/seven"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<Button
android:id="#+id/eight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<Button
android:id="#+id/nine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:id="#+id/zero"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"></LinearLayout>
</LinearLayout>
here is the output