I have ScrollView with LinearLayout and button inside:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="#+id/layout_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/layout_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#color/card_color"
android:orientation="vertical"
android:padding="10dp">
</LinearLayout>
<Button
android:id="#+id/button_leave"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="#string/leave" />
</LinearLayout>
</ScrollView>
Then in code I add view to layout_list:
View view = LayoutInflater.from(this)
.inflate(R.layout.item_member, mLayoutMemberList, true);
If I add not many items, then button_leave is visible. But if I add a lot of items (more then showing on the screen) then button is not visible on the screen even if I scroll down.
Update:
Looks like it is bug of android.support.design.widget.CoordinatorLayout. I change it to simple linear layout and all work good.
Try like this:
I think layout view is working fine and try below code,
LayoutInflater inflater = context.getLayoutInflater();
View rowView=inflater.inflate(R.layout.layout_list, null, true);
Related
I have a ListView with 2 footer views. The first one is a bunch of TextViews, while the second one is a button. I'm trying to fix the second footer so that it always shows at the bottom of the screen.
I tried the following:
1. alignParentBottom = true
2. layout_gravity="bottom"
3. footerView2.bringToFront()
And combinations of the above. But none of them worked out. How can I achieve this?
UPDATE
I shouldn't have added the View which I always want on the screen (fixed) as footer.
I just added the wannabe-fixed-view with the listView. Did alignParentBottom = true and also view.bringToFront(). It worked out for me.
Separate your ListView and bottom footer. The idea is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/btn_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Bottom button"/>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/btn_bottom"/>
</RelativeLayout>
Create separate xml file which contain all textviews and button you want as footer part.Then bind this xml as a footer of listview. You can binf footer with listview by this method: listview.addFooterView(footerView);
For example:
View footerView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.listviewfooter, null, false);
spDate = (Spinner) headerView.findViewById(R.id.spdate);
llDatepicker = (LinearLayout) headerView.findViewById(R.id.lldatepicker);
rvDatepicker = (RecyclerView) headerView.findViewById(R.id.rvdatepicker);
rvTimepicker = (RecyclerView) headerView.findViewById(R.id.rvtimepicker);
lvAddress.addFooterView(footerView);
If you are Trying to add a View which will be shown even if we scroll the List Up or Down... u can do something like this. I had done this before But as a header.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="#+id/new_container"
android:background="#color/white"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="LOAD EARLIER MESSAGES"
android:id="#+id/loadMore"
android:background="#90F58220"
android:visibility="visible"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listContainer"
android:layout_below="#+id/loadMore"
android:layout_above="#+id/container">
<ListView
android:id="#+id/messagesContainer"
android:transcriptMode="normal"
android:dividerHeight="0dp"
android:divider="#null"
android:stackFromBottom="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/container"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:background="#ffffff"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:layout_height="wrap_content" >
</RelativeLayout>
The LoadMore Button is always visible on the Top of the List...
To add it to footer, Just Change
android:layout_below="#+id/loadMore"
android:layout_above="#+id/container"
to
android:layout_above="#+id/loadMore"
I have been trying to add Button's below a GraphView, and all these elements are part of a Fragment. Tried many approaches but none of them worked properly.
This is the layout file for the Fragment (fragment_graph.xml).
<FrameLayout 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"
tools:context="com.nma.util.sdcardtrac.GraphFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/graph_fragment_layout"
android:orientation="vertical"
/>
</FrameLayout>
And this is the Java code dynamically adding a graph and button, placed in the Fragment's onViewCreated (View view, Bundle savedInstanceState).
storageGraph = new LineGraphView(getActivity(), graphLabel);
storageGraph.addSeries(graphSeries); // More config calls follow
...
LinearLayout view = (LinearLayout)getView().findViewById(R.id.graph_fragment_layout);
Button button = new Button(getActivity());
button.setText("Test");
view.addView(storageGraph);
view.addView(button);
The Button is not visible though I have set orientation to vertical for the LinearLayout containing it.
EDIT - solved!
I found that nesting the graph under its own LinearLayout and the buttons under another LinearLayout, and both of these wrapped in a LinearLayout fixed the problem! The LinearLayout containing the graph must be weighted (I chose a weight of 0.8).
Layout file looks like:
<FrameLayout 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"
tools:context="com.nma.util.sdcardtrac.GraphFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/graph_fragment_wrap"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.8"
android:id="#+id/graph_fragment_layout"
android:orientation="vertical" />
<LinearLayout
android:id="#+id/graph_buttons"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/ic_navigation_previous_item"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_navigation_next_item"/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
I've just tried it and it works. Perhaps your graph is taking all the available space, so added button is below the screen? Try to wrap your LinearLayout into a ScrollView and see if there is a button in the bottom.
I'd like to achieve such a layout, where user got 2 control panels. He is able to switch from first to second by pressing button and vice versa.
Already have tried to use LayoutInflater, however, without success :/
The main reason, why doing it with 2 different layouts is, that buttons will be almost on the same position, so i'd like to prevent all that mess in one layout and create 2 separate control panel layouts.
Here are my layouts:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/control_panel_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="5">
<!-- Here comes including layouts-->
</RelativeLayout>
</LinearLayout>
control_panel_1.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/control_panel1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/btn_action1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_action_selector"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/btn_action2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_action_selector2"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/btn_action1"
android:layout_marginRight="50dp"/>
<Button
android:id="#+id/btn_action3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_action_selector3"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/btn_action1"
android:layout_marginLeft="50dp" />
</RelativeLayout>
control_panel_2.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/control_panel1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/btn_action3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_action_selector4"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/btn_action4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_action_selector5"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/btn_action3"
android:layout_marginTop="20dp"
android:layout_marginRight="60dp"/>
</RelativeLayout>
MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_root);
RelativeLayout controlPanelLayout = (RelativeLayout) findViewById(R.id.control_panel_layout);
//Inflate first control panel on activity start
LayoutInflater layoutInflater = (LayoutInflater)
this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View controlPanel1 = layoutInflater.inflate(R.layout.control_panel_1.xml);
controlPanelLayout.addView(controlPanel1)
}
EDIT:
As shown in the image, let's say activity starts with Screen1 and once user press Btn1, Screen2 appears...as you can see, only control panel has been switched.
however, it won't inflate that layout at start of application...
Thanks in advance for any suggestions, hints...
Inflate your control panel in onCreateView() and when handling button click (to change panel). The code should be somewhat like this:
private void inflateYourPanel(int panelLayoutID, ViewGroup placeholder) {
placeholder.removeAllViews();
View view = LayoutInflater.from(mActivity).inflate(panelLayoutID, placeholder, false);
//find your views and set values and listeners
placeholder.addView(view);
}
Edit: placeholder may be any layout (control_panel_layout) inflated when starting activity etc
Still may be you'd better look at Fragments - it may fit your purpose better and provide more scalability
I am working on android project where I have an activity which is using the theme holo dialog.
Within the dialog I have a list view and what I want to have is at the bottom always on show a linear layout which contains two buttons next to each other. The list view is populated by retrieving data from the call log and populating the adapter of the list.
The problem I am having is the list view always shows on top taking up the whole dialogue with the buttons at the bottom, with the content of the list overlapping the buttons. I want the list to be within the space of the top of the dialogue to the top of the linear layout button group. Below is the code for the main content view. This layout is set using the setContentView in the onCreate method
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
<LinearLayout android:id="#+id/call_log_select_host_button_group"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<Button android:id="#+id/call_log_select_btnCancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Block"/>
<Button android:id="#+id/call_log_select_btnBlock"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel" />
</LinearLayout>
</RelativeLayout>
I'm not sure if it makes any difference but just in case the below is how I am populating the list and setting the view.
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
CallInformation callInformation = (CallInformation)arrayList.get(position);
LayoutInflater inflator = (LayoutInflater)context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflator.inflate(R.layout.call_log_selection, parent, false);
ImageView imageView = (ImageView)rowView.findViewById(R.id.call_log_selector_image);
if (callInformation.type == android.provider.CallLog.Calls.INCOMING_TYPE)
{
imageView.setImageResource(android.R.drawable.sym_call_incoming);
}
else if (callInformation.type == android.provider.CallLog.Calls.OUTGOING_TYPE)
{
imageView.setImageResource(android.R.drawable.sym_call_outgoing);
}
else if (callInformation.type == android.provider.CallLog.Calls.MISSED_TYPE)
{
imageView.setImageResource(android.R.drawable.sym_call_missed);
}
CheckBox checkbox = (CheckBox)rowView.findViewById(R.id.call_log_selector_checkbox);
checkbox.setText(callInformation.content);
checkbox.setTag(callInformation.telephone);
return rowView;
}
}
The below code is the XML layout that is inflated by the adapter get view function
<?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="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView android:id="#+id/call_log_selector_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:layout_gravity="center"
android:src="#android:drawable/stat_sys_phone_call"/>
<CheckBox android:id="#+id/call_log_selector_checkbox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
Thanks for any help you can provide.
Try telling your ListView to stay above your LinearLayout
<ListView android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/call_log_select_host_button_group> // Add this line here
</ListView>
I have implemented a ListView in my application using a custom implementation of CursorAdapter. My problem is, that whenever I fling to scroll quickly to the bottom of the list (right after launching the application), I sometimes end up with all the ListView items drawn overlapping each other. If I scroll back up or touch one of the items, they become properly arranged.
Here is how it looks after I quickly scroll down :
http://i.stack.imgur.com/cTcfD.png
Here is how it looks when I am select-ing one of the items :
http://i.stack.imgur.com/ZTRSt.png
Here is the XML for my ListView :
<ListView
android:id="#+id/all_reminders_list"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_alignParentLeft="true"
android:clickable="true"
android:dividerHeight="1.0sp"
android:animateLayoutChanges="true">
Here's the newView(..) method of my custom CursorAdapter :
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.view_list_item, parent, false);
return view;
}
And this is the bindView(..) method :
public void bindView(View view, Context context, Cursor cursor) {
TextView whatTextView = (TextView) view.findViewById(R.id.item_what_text);
whatTextView.setText(cursor.getString(1));
TextView whenTextView = (TextView) view.findViewById(R.id.item_when_text);
if(cursor.getInt(9) != 0) // DONE_FLAG = 1 (completed)
{
//Arrow visibility
ImageView arrow = (ImageView)view.findViewById(R.id.list_item_arrow);
arrow.setVisibility(View.INVISIBLE);
//Text color
whatTextView.setTextColor(Color.LTGRAY);
whenTextView.setTextColor(Color.LTGRAY);
//WHEN text
whenTextView.setText(TimeCalculationHelper.getCompletedTimeString(cursor.getLong(2)));
}
else // DONE_FLAG = 0
{
//Arrow visibility
ImageView arrow = (ImageView)view.findViewById(R.id.list_item_arrow);
arrow.setVisibility(View.VISIBLE);
//Text color
whatTextView.setTextColor(Color.BLACK);
whenTextView.setTextColor(Color.BLACK);
//WHEN text
whenTextView.setText(TimeCalculationHelper.getTimeRemainingString(cursor.getLong(2)));
}
}
I've also noticed that I have been able to replicate it only when my device (Galaxy S2) is in power saving mode. Is there something I should be doing differently here? Thanks in advance!
EDIT : Including the list item's layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="2dp">
<TextView android:id="#+id/item_what_text"
android:lines="1"
android:maxLines="2"
android:textSize="22dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="3dp"/>
<TextView android:id="#+id/item_when_text"
android:lines="1"
android:maxLines="1"
android:textSize="14dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="13 minutes"
android:paddingBottom="2dp"
android:layout_below="#+id/item_what_text"/>
<ImageView
android:id="#+id/list_item_arrow"
android:src="#drawable/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</RelativeLayout>
I also faced the same problem, with List items in my ListView overlapping each other whilst scrolling.
My fix:
I just specified a background for the parent layout that contained the ListView in question. Previously it was transparent.
I had the same problem and found it was caused by setting the animateLayoutChanges attribute to true on the listview.
Unfortunately I lose the animation of the listview by removing it but at least it draws properly when scrolling fast.
Giving the parent layout a background also appears to fix the issue, as mentioned by Pavan. Will experiment and change my answer if I discover issues with the background change.
For solving this ,i have one more solution:
I faced problem by using this layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
android:paddingTop="4dip"
android:dividerHeight="0dp"
android:divider="#null"
android:cacheColorHint="#00000000"
android:listSelector="#color/transprent_editbox"
android:focusableInTouchMode="false" />
</RelativeLayout>
In order to solve that Problem,i just did few modifications on Above layout,those are:
1)Changed top layout from Relative to Linear Layout.
2)Put my ListView in other Relative Layout ..
i did like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
android:paddingTop="4dip"
android:dividerHeight="0dp"
android:divider="#null"
android:cacheColorHint="#00000000"
android:listSelector="#color/transprent_editbox"
android:focusableInTouchMode="false" />
</RelativeLayout>
</LinearLayout>
After using this,my problem is solved.
1.
in my opinion, height is wrap_content
because listview is restore row
2.
other opinion is write this code android:cacheColorHint="#00000000" in ListView
I also faced the same problem and found that animateLayoutChanges attribute causing the problems.
So i changed
android:animateLayoutChanges="true"
to
android:animateLayoutChanges="false"
and it worked.