android - Place Button below ListView to fill all available space but Button should have min Height -
How to move the button below the ListView to follow the next conditions:
- ListView
- The list available below is
- The calculation of the height of the list view is very long if you know the exact height of the list view element and know that In the list view are objects only in this height, you can calculate the height of the item once and then by multiplying the height of the items depending on the height of the items, you can calculate the height of the list view.
- Basically if you have to use this (I have used the NoActionBar.Fullscreen topic for simplicity in this example), you would have to reduce the height of the statusbar height and the action bar
- Code> dimens.xml needs to define the height of the minimum button load the file and its value
onCreate . In this example, I use continuous value for simplicity.
As you can see, not a great solution, but I hope it will be helpful.
Reference:
- ListView content is too large if the bottom button should be scrolled down to ListV and ListView < P>
I believe it's impossible to do such a layout using XML layout Is obtained.
You can try it dynamically.Create a test application with themes just like a proof-concept:
& lt; Style name = "Aaptim" Original = "Android: Theme.Holo.Light.Actionbar. Fullscreen" & gt;
Create Activity Layout
activity_main.xml like this:
Android: Android: Android: Android: Android: layout_width = "match_perrent" Android: layout_heck = "match_perrent" Android: layout_language parentbottom = "true" Android: text = "button" /> & Lt; / RelativeLayout & gt;
And in this activity it works:
the expansion of the public class MainActivity Activity (Private Button mButton; Private List View mListView; Personal Static FINAL END BUTTON_MIN_HEIGHT = 300; Private array adapter & lt; string & gt; mAdapter; @ override protected form to zero (bundle saved instenstate) {super.naught (savedinstenstate); setContentView (R.layout.main); final list & lt ; String & gt; Value = New Arreelist & lt; string & gt; (); MAdapter = New Array A Apter & lt; string & gt; (this, android rt.impl_l_litimi, android.r.edtext1, value); mListView = (ListView) findViewById (R.id.listView); mListView.setAdapter (mAdapter ); MButton = (button) findViewById (R.id.button); MButton.setOnClickListener (New View.OnClickListener) {@Override Public Zero (click view) {values.add ("something"); Invalid Voices ();}});} Private intuscite () {display display = getWindowManager (). GetDefaultDisplay (); Point size = new point (); display.getSize (size); Return size. Y; } Private Inc getListViewHeight () {int listviewElementsHeight = 0; (Int i = 0; i & lt; mAdapter.getCount (); i ++) {see mView = mAdapter.getView (i, null, mListView); MView.measure (see. Mauser's Speak., MacMisitorsPP (0, see Major SPPNSPIEFIEDE), see MeasureSpeaceMakeMagiersSpec (0, View.mijsSpec. Undefined)); ListviewElementsHeight + = mView.getMeasuredHeight (); } Return List View Elements Hits; } Private invalid invalid view () {mAdapter.notifyDataSetChanged (); Int buttonhight = deskscreen () - getListViewHeight (); Log.e (MainActivity.class.getSimpleName (), "Button height:" + buttonHight); If (Butlite & lt; BUTTON_MIN_HEIGHT) {buttonHeight = BUTTON_MIN_HEIGHT; } Relative layout. Layout Paramax LayerTemplate = (Relative Layout. LayoutParam) mButton.getLayoutParams (); LayoutHalfHeight = ButtonHight; MButton.setLayoutParams (layoutParams); }}
Initially we have a full screen button and an empty list view. Click on the button to see another item will be added to the list and the size of the button will be replaced and the correct value will be applied. There are methods
getScreenHyight () and
getListViewHeight () , which help us to calculate the desired button height, to define the minimum height for the button we
BUTTON_MIN_HEIGHT continuously provide. The height of the button We calculate the bus by decreasing the height of the list view from the height of the screen.
This example is awesome and is not optimized. Problems:
Comments
Post a Comment