I have a header section that I would like to scroll with a list view below. The problem is that I have a toggle below the header section that allows the user to switch between two list views. What would be the best way to have a header section scroll in sync with the two list views below?
I can share a short overview to help you:
<ScrollView ..>
<LinearLayout>
<HeaderView></HeaderView>
<ToggleButton></ToggleButton>
<ListView></ListView>
<ListView></ListView>
</LinearLayout>
</ScrollView>
The tricky thing is: You have to flip the visibility of the two listView by visible and gone in the toggle button.
1st click on toggle will make it
listView1.setVisibility(View.GONE)
listView2.setVisibility(View.Visible)
2nd click on toggle will make it
listView2.setVisibility(View.GONE)
listView1.setVisibility(View.Visible)
Related
I'm trying to change the tab as we scroll through the recycler view.
I have listed the items in single recycler view.
So when i reach the header ( for example Breakfast then Breakfast tab should be active ) of each section how to change tab accordingly?
The above gif explains my query. Please suggest me a solution.
I have an android app where it has two list views in same screen. With one ListView i can get right result(I can highlight the pressed item). If i set the Adapter of the second ListView with setOnItemClick() method of first Listview, my first Listview's setSelected() method don't working. Can anyone help me?
And I also have *.xml files for state_selected tags. I want to highlight only one selected item and not multiple items.
If you just need to change the color of the currently selected item in the ListView, just use change choiceMode attribute to "singleChoice", and select the color using listSelector attribute
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:choiceMode="singleChoice"
android:listSelector="#android:color/darker_gray"
/>
I'm trying to make a simple app in android studio but running into trouble with layout whenever I place down a RadioGroup. In my first image here I've created a RadioGroupand dragged two RadioButtons into it by dragging them to the radiogroup option on the component tree trying to drop them into the radiogroup on the layout thing is impossible as the radiogroup is completely invisible on it.
I drag a button below it, lining it up with the center, and the box that shows where the buttons going to go shows it being below the radiogroup. But once I release the mouse button, the button im attempting to place ends up here.
I've been fighting with android studio for a while now but if I get the button even remotely close to the RadioGroup it gets catapulted up the screen, and I don't have enough room if I place the button way down low for my other elements.
tl;dr
radiogroups are catapulting any elements underneath them above them. its probably a layout or gravity issue or something like that. but I don't know how to fix it and would like my buttons to not be underneath all the other elements kthx.
I'm not sure what is causing your issue, because you aren't providing enough information. But If you want the button to appear under your radio group, then in your xml file, give your radio group an id android:id="#+id/radioGroup" and in your button add android:layout_below="#id/radioGroup".
Try to android:layout_below="#+id/radioGroup" in your button.As your are using Relative Layout by default it takes you top while dragging.Here is full Button view.
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:id="#+id/button"
android:layout_below="#+id/yourRadioGroupId"
android:layout_centerHorizontal="true" />
I have a header at the top and a recyclerview underneath it. Like so:
<LinearLayout>
<LinearLayout>
<ImageView/>
<TextView/>
<TextView/>
</LinearLayout>
<RecyclerView/>
</LinearLayout>
I also have a view with a header and two recyclerviews. Like so:
<LinearLayout>
<LinearLayout>
<ImageView/>
<TextView/>
<TextView/>
</LinearLayout>
<Recyclerview/>
<Recyclerview/>
</LinearLayout>
When I scroll up on the recyclerview on the first layout, the header stays there. I want the header to go up and out of the view as I scroll down the recyclerview.
On the second layout, each list is short and could fit on the screen individually, but together the second one goes offscreen (i'm using this layout manager to make the layout wrap content). This would be fine, however when you scroll up on the first recyclerview, it only tries to scroll itself (which is can't because there's nothing to scroll) so you can't scroll to see what's offscreen. You also can't scroll on the header to go offscreen.
In both cases, how can I get the recyclerview to scroll with its parent?
In the first case, you can use CollapsingToolBarLayout.
There're number of nice tutorials/examples about it:
antonioleiva.com/collapsing-toolbar-layout
http://android-developers.blogspot.co.uk/2015/05/android-design-support-library.html
CoordinatorLayout with RecyclerView & CollapsingToolbarLayout
https://www.youtube.com/watch?v=kXmESQ0v6fU
In the second case, I'd suggest to replace 2 RecyclerViews by 1 with different viewTypes for the sake of keeping views recycled during scrolling.
<NestedScrollView>
...your views here...
<RecyclerView
android:NestedScrollViewEnabled="false"/>
</NestedScrollView>
I'm planning an app to have lots of menu items in landscape mode. However, the menu implementation by android seems to have some limitations causing menu items to hide even with a lot of empty space. According to them, this is because of design principles:
When contained within the action bar there is a finite maximum of
action items based on the device's density-independent width. The
action items can also not cover more than half the width of the action
bar.
Action bar - ifRoom option leaving too much space
Also:
To override this behavior and have more items, it would be necessary to build a toolbar and have as many buttons as the screen would support. However, I will be reinventing the wheel, because the android menu has a lot of integrations with the device menu button, overflow behavior by collapsing, tooltip by pressing, etc...
Still, I researched some apps and I found that Squid (old Papyrus) does exactly what I seek. It displays far more than what android limits to and it seems to be exactly the android menu behavior but allowing more items.
My question is: What the recommendation to achieve this? Is there a way to overcome the android limitation with a few "hacks" or should I build a whole new custom menu to change a minimal configuration? Can I inflate the android menu and place it somewhere else?
Thanks.
I guess what you need in this situation is to use ActionBar custom view, I don't really know if there is any other way to
do that but i know a custom view will do the job, and by the way it's very easy.
See the example bellow:
onCreate():
final ActionBar actionBar = getActionBar();
actionBar.setCustomView(R.layout.custom_view);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
Custom View:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<!-- Your Items -->
</LinearLayout>
Hope this will help.