I am following a tutorial on grid layout. In particular, I am replicating Suragch's answer.
The code itself is working fine, except I would like to center the RecyclerView in the activity.
I've tried
android:gravity="center"
and
android:layout_gravity="center"
on both the RelativeLayout AND RecyclerView, but neither works.
Also, I would like to eliminate the gaps between each column. Does anyone know how to go about doing this?
Try android:layout_centerInParent=true into <RecyclerView>
Depending on your parent Layout
If its RelativeLayout then
android:layout_centerHorizontal=true in RecyclerView
if its LinearLayout then
android:layout_gravity=center_horizontal in RecyclerView
One more interesting thing you can do in Adapter
the main parent Layout in adapter
try doing this
android:gravity=center_horizontal in main layout of adapter
Related
As the title says. I'm trying to display extremely complex layout with a full height of the viewport but I need it scrollable because under it there is a simple recyclerview with some items. I already thought about putting everything inside a multi type recyclerview adapter but the logic of the upper layout is so complex that I don't think it's possible.
I tried using NestedScrollView with fillViewport set to true but I'm stuck defining dimensions of this upper layout and recyclerview below it. Everything needs to be inside one layout because scrollview can't have more than one child, but when I put everything in a linearlayout and set the upper layout to match_parent it's showing fullscreen until data loads in the recyclerview below it. Then it's treating this upper layout as if it was wrap_content.
I'm out of ideas how can I do something like this. Preferably best would be to have some sort of ViewGroup which would support scrolling and resize the recyclerview below it as we scroll, but I'm not sure how to do it.
you need to set the layout to something like this:
<NestedScrollView - height:match_parent>
<LinearLayout - height:wrap_content>
<LinearLayout(topview) - height:wrap_content/>
<RecyclerView - height:wrap_content />
</LinearLayout>
</NestedScrollView>
And then you programmatically change the height of the "topview" to equal nestedscrollview.
Basically, I have a Scroll View and it contains several child inside Linear Layout. Now, I want to show a View constantly on the top of the screen when it is scrolled down.If it is scrolled up everything should be as it was earlier.
Can anyone just help me out? Any help would be appreciated! (Thanks in advance).
Define a ObservableScrollView class entends ScrollView.
Then write your layout xml like this:
<RelativeLayout>
<View/>
<ObservableScrollView>
</ObservableScrollView>
<RelativeLayout>
In ObservableScrollView class,focus on this onScrollChanged function.
Change the visibility of your target view by param 'y'.
I have an Activity where there is a Linear Layout which occupies nearly half of the screen and below that I need to keep a listview which has hold any number of items. Now initially I was doing like this
<ScrollView>
<LinearLayout>
</LinearLayout>
<ListView>
</ListView>
</ScrollView>
But reading all the threads I think it is not really a good idea keeping listview inside Scrollview. Also I am facing a lot of issues like the height of the Listview is not proper.
So how do I keep the layout and listview inside the same activity without using ScrollView?
It is not recommended to include a scrolling View (ListView) inside a ScrollView. What you want to achieve can be done by adding a HeaderView which can be inflated from another XML.
LinearLayout ll = inflater.inflate(R.layout.my_layout, null);
listView.addHeaderView(ll);
Hello i have an Relative Layout in Android, with EditTexts, TextViews, one Spinner and RadioButtons. It's a lot of things for only one screen, so i need to change for a ScrolView. When i try add the line in the first line and on the last Row, I have problems.
How can i add a scroll on my screen without lose all the layout I built so far?
so i need to change for a ScrolView
You do not need to change "for a ScrolView". You need to wrap your RelativeLayout in a ScrollView.
How can i add a scroll on my screen without lose all the layout I built so far?
Put a ScrollView around your RelativeLayout:
<ScrollView>
<RelativeLayout>
<!-- existing stuff here -->
</RelativeLayout>
</ScrollView>
As #CommonsWare has said, you can just wrap your current layout with a ScrollView.
Just keep in mind that a ScrollView must have only one child.
Folks, I have the following layout: http://dpaste.com/hold/755261/
It has two seekbar widgets. Both are not showing. If I move them to the root linearlayout, they appear, otherwise not. I need them to be inside the first linearlayout. Anyone could help me how to achieve that?
It looks like you need to put the following in your third LinearLayout:
android:layout_weight="1"
Change the second LinearLayout height to wrap_content. If the content doesn't fit on the screen, then maybe you have to use a ScrollView.