Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Layout - fill the rest of the space except

I have a relative layout. For simplicity, there is an ImageView, EditText, and Button:

  • The ImageView is a banner with a fixed height
  • Below that is and the EditText where android:layout_width="fill_parent"
  • Below that is a Button with a fixed width and height

The problem is I want the editText to fill the leftover height of the screen. put and image on the top, a button on the bottom, and in the middle and edit text that takes up the rest of the space.

What property would i have to work with to get something similar to this?

like image 909
AndrewJM Avatar asked Sep 05 '11 22:09

AndrewJM


People also ask

What does layout_ weight mean in Android?

LinearLayout also supports assigning a weight to individual children with the android:layout_weight attribute. This attribute assigns an "importance" value to a view in terms of how much space it should occupy on the screen. A larger weight value allows it to expand to fill any remaining space in the parent view.

What is constraint layout in Android?

A ConstraintLayout is a ViewGroup which allows you to position and size widgets in a flexible way. Note: ConstraintLayout is available as a support library that you can use on Android systems starting with API level 9 (Gingerbread). As such, we are planning on enriching its API and capabilities over time.

Why use constraint layout?

ConstraintLayout provides you the ability to completely design your UI with the drag and drop feature provided by the Android Studio design editor. It helps to improve the UI performance over other layouts. With the help of ConstraintLayout, we can control the group of widgets through a single line of code.

How can I get remaining height in android?

You can use set the layout_width or layout_width to 0dp (By the orientation you want to fill remaining space). Then use the layout_weight to make it fill remaining space.


1 Answers

For this purpose, there is LinearLayout with layout_weight property. Use LinearLayout for holding these 3 elements. For Button and ImageView, set layout_height as wrap_content. For EditText set layout_height="0dp" and layout_weight="1".

like image 152
peter.bartos Avatar answered Nov 10 '22 11:11

peter.bartos