Laying out views below a ScrollView/ListView - android

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);

Related

Android view partly on top of scrollable active listview

I'm creating a music player where I have a listview-activity to choose songs from. Whenever I choose a song I need a smaller view to pop-up on the bottom of the screen, on top of the listview, just like edit-text when the keyboard pops-up.
But I also want to still be able to scroll the listview(when the song is playing) without the smaller view disappearing from the screen.
The smaller view will contain buttons for the player.
Is this possible?
If so, what is the best way to do this?
Any ideas?
A simple way of doing this could be to reserve as space for the smaller view and then set it's visibility to invisible, then when the song is picked set it's visibility to visible layoutelement.setVisibility(View.VISIBLE);
where your layout element is the piece who's visibility you are changing.
Since your whole layout is within a scroll view when your layout visibility is set to visible the other components of your layout will be pushed below and you'll be able to scroll through it all.

How to display a group of images from drawable to let the user pick one (Android Studio)?

I currently have an activity with a horizontal scrollview, and inside it I have an add button (ImageView) to let the user add some images to the same horizontal scrollview after clicking it. How can I display a group of images from app resources (such as drawable) as a sort of "pop up" to let the user pick one, without changing the current activity?
You need to create recyclerView with horizontal layout. The adapter of the recyclerView will have the functionality to implement a button click. The onClick of the button will add items to the adapter. These items may contain your required images.On every button click you need to call notifyDataSetChanged.
This can be solved by inflating a custom xml layout (containing a GridView) on an AlertDialog. To display the images on the GridView you need to create and set a custom adapter to it. The adapter shall have a function getView(), which will return each of the Views to be shown on Grid cells. You can also use Picasso Library to load the images.
Here is a brief tutorial
http://www.101apps.co.za/articles/gridview-tutorial-using-the-picasso-library.html
Hint: Remember to define the number of columns of the grid, and calculate the size of each image based on the screen size. This way you can fit the amount you like on each row. You can do this for both portrait and landscape orientations by overriding the function onConfigurationChanged.
Hint 2: Remember a GridView already has the scroll property, which needs to be activated (android:scrollbars="horizontal"). Using a ScrollView as parent of a GridView will cause it to wrap the image, even with MATCH_PARENT property activated, causing layout problems.

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.

In android layout how do I align elements underneath a listview regardless of the listview's height

I've got a listview and I want there to be two textviews and two buttons underneath it (3 of which may be hidden in the code). Every single layout I tried either results in the four elements being anchored to the bottom of the screen even when the listview is only a few lines, or getting pushed off altogether if the listview gets big enough. Any ideas?
It sounds like you've used android:layout_below="#id/listVieId" and android:layout_alignParentBottom="true" as these would give the results you mentioned. It sounds like what you want is addFooterView(View v)
Note what the Docs say
NOTE: Call this before calling setAdapter. This is so ListView can wrap the supplied cursor with one that will also account for header and footer views.

why listFragment will automatically Resize

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.

Categories

Resources