why listFragment will automatically Resize - android

My UI Layout is like this;
My question is, when the screen has enough space for FrameLayout's ListFragment's Fragment,
the ListFragment will be fully displayed. but if the screen is too small, ListFragment will be automatically compressed and cannot be fully displayed their contents.
I look forward to the effect is that if the screen is too small, scroll bars will appear, rather than changing the height of ListFragment.

Using the response of S.D, I have had the same problem with the ScrollView and ListFragment, the list always has the same height despite it is forced on the layout. Leaving the FrameLayout out of the ScrollView this problem disappears.
In your case, could be a good idea make your View a custom ListView where each item will be different. First item could be the first TextBox, the second item will be the first Fragment, and so on.
I hope that this response be helpful to you.

Related

ListView Only add enough items to fill screen

I have a listView that is populate via a RSS feed. The height of each item on the ListView can vary depending on the length on the content. Is there a way to only add enough items to the listView to fill the screen (the listView has a fixed height).
For example if each item only has one line of text I can fit 7, but if they have two lines of text I can only fit 5. I want to be able to programmatically decide when to stop adding items. I don't want the ListView to have to scroll.
EDIT
Let me rephrase. I don't want to just solve it but scrolling down. There may at some point in the development be content that gets added below the screen and requires scrolling but even in that case I don't want half an item showing at the bottom. Basically I don't want broken/half items showing at the bottom, if it's on the screen it should be the whole item that is showing. If not it should be below the bottom of screen.
Try using a normal Linear Layout and when adding the inflated row, override the onMeasure to know if it fits on the screen.

How to make the entire screen containting a (LinearLayout + ListView) scrollable

I have an Android fragment in which contains a Vertical LinearLayout with two layouts inside it: Another inner Vertical LinearLayout (which takes at least half of the screen) and a ListView (which shows a number of smaller Views). A good way to think about it is something like a facebook post along with several comments showing below it.
The problem I am facing is that the the inner LinearLayout is not scrollable and therefore parts of the ListView stays outside of the screen and there is no way to scroll the screen up to see the entire ListView (the inner layout could possibly take up the entire screen). Placing the entire layout inside a ScrollView is also known to be a bad practice.
I know one solution is to make the entire layout to be a ListView with the first cell to be the inner LinearLayout, followed by the cells from the original ListView. That however has its own issues: It is harder to recycle the views in the ListView, and generally I also see it as a bad practice where one cell has a different behavior from all other cells in the ListView.
Is there a better solution to this? I can imagine this is a typical problem and I hope to find a better solution than above.
This may help you:
ListView yourListView = new ListView(this);
yourListView.addHeader(getHeaderView());
You can also add footer to a ListView. When you do this, the header(or footer) will become part of the ListView, and so it will be scrollable. You can find the document here: http://developer.android.com/reference/android/widget/ListView.html.

Adjusting fragments height according the pixel position scroll on a list inside one of the fragments (Android)

Ok, I have a LinerLayout vertical in which there are three fragments, lets say: HeaderFragment, SubHeaderFragment and ListViewFragment (fragment with listview in it). These are put in the layout in this order, width set to match_parent. The header and subheader fragments have a defined height, lets say 100dp each. The list fragment's height is set to wrap_content.
Now, what I want to do is that when the list fragment is scrolled down, the SubHeader fragment should loose its height (according to the amount scrolled) until it disappears and the user checks the list. If the user scrolls back up to the beggining of the list the SubHeader fragment should get its height back, again according to the scrolling.
This can be seen in several Apps, for better use of the screen size.
I have researched quite a bit, but I found no simple solution to this. One would be to keep track of the scrolling position of the list and reset the heights dynamicly while this is done. Which is trouble because as far as I know the scroll position for the list must be calculated and I am dealing with fragments that have no layout params.
Another idea I had was to put the SubHeader and the List Fragments in a scrollview within the linear layout, but that destroys my list within its fragment and people say it shouldnt be done due to bad performance.
Is there a decent simple solution for this? Thanks for any help in advance!

How to create a gridview with spacing at the top

I was looking to create a GridView that stretches across the entire screen. However, when the user first opens the screen, the top of the first item should be about halfway up the screen.
For example lets say we have a GridView of 12 items displayed 3 x 4. When the user first opens the screen, only the first six items would be seen with a large margin at the top of the screen. The user can then scroll the list to see the other items. The top items would eventually reach all the way to the top of the screen.
If I was using a ListView, this is simple. I merely create a 0dp headerView with a large top margin. But, GridViews do not allow for headers. What is the best way to handle this situation?
Normally, you DO NOT make a GridView inside a ScrollView. It's not recommended! But sometimes you have no choice and you need to addHeaderView() on a GridView (But I repeat, it isnt recommended).
So, to make this happen, you have to make a custom GridView. This answer will be usefull in your case: Grid of images inside ScrollView
I had a same situation and I used this one: HFGridView by #SergeyBurish! Very simple and really great. (See the last answer here: A GridView with header and footer).
Hope this will be helpful.

Laying out views below a ScrollView/ListView

My question is a bit specific, I have a ListView of items above a button all inside a dialog. I want my ListView to never be greater than 280dip but always have the button below the ListView, no matter how large this ListView may be. My concern is when the dialog is switched to landscape mode, the button disappears because it is pushed out of the view by the ListView above that I have set to have android:layout_height="280dip". Obviously, this means that the ListView will always be 280dip, but is there a way to make it so that the ListView can change its size so it can always fit the button below it no matter the screen size/dimensions? I don't want to fill the parent of the height in the dialog because I don't want the dialog to be stretched out all the way in portrait mode. I'm sure there is a simple solution to this, but I wasn't sure how to word it in a manner that was more general.
If you want a View to take up the rest of layout, you should set a weight for the View.
Try giving the following settings for the ListView and see what happens.
android:layout_weight="1"
android:layout_height="0dp"
If you want the button to always be right below the listview and keep it visible despite the varying screen sizes, just create a new layout that contains a button and initialize that layout in your java code. Then do listView1.addFooterView(layoutView) and the layout with the button will be attached to the bottom of the listview. This can help you further with setting a footer view to the listview.
View footerView = ((LayoutInflater)MyActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
listView1.addFooterView(footerView);

Categories

Resources