Reputation: 67
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>
Upvotes: 1
Views: 1816
Reputation: 21736
"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:
"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~
Upvotes: 1
Reputation: 625
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>
Upvotes: -1
Reputation: 521
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>
Upvotes: 0
Reputation: 672
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>
Upvotes: 0
Reputation: 22064
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
Upvotes: 1
Reputation: 3486
<ScrollView ..
<RelativeLayout..
<LinearLayout // vertical orientation
<ListView ../>
<LinearLayout // your linear layout
layout_below="@+id/listviewid"
</LinearLayout>
</RelativeLayout>
</ScrollView>
Try this view hierarchy.
Upvotes: 0