10565

Android fill_parent issue

HI there. This is my layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ListView android:id="@+id/lv" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@android:color/white" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/lv" /> </RelativeLayout>

When I run this the list view occupies full screen. What I want is list view to be full screen except button area without mentioning dp. Thanks

Answer1:

@mnish is quite right except that in Android 1.5 you have to declare ids before using them.

<ListView android:id="@+id/lv" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@android:color/white" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/lv" />

You can use layout_above, layout_below, layout_toLeftOf, ...

Answer2:

After trying out some possibilities I found this to be helpful

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ListView android:id="@+id/lv" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@android:color/white" android:layout_above="@+id/bt"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/bt" android:layout_alignParentBottom="true"/> </RelativeLayout>

Thanks all of you for answers.

Answer3:

I think a LinearLayout is more suited here.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" /> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>

(Yes, wrap_content is correct on ListView's layout_height, the layout_weight="1" will ensure it expands as much as possible)

Answer4:

I guess you can do this:

write:

<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/lv" />

before:

<ListView android:id="@+id/lv" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@android:color/white" />

like this:

<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/lv" /> <ListView android:id="@+id/lv" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@android:color/white" />

but I am not sure

Recommend

  • How to use the grid-list in Angular Material, so that all page content is displayed between the head
  • A few memory management questions involving class destructors and delete operator?
  • Why function parameter occupy at least 4 bytes stack on x86?
  • How to rbind vectors into different columns, leaving NAs in remaining cells
  • In Android, using java: determine string length of mix-bytes character String?
  • Getting the model ID from a Django form after having saved it
  • media player does not work in my code
  • How to remove just the index name and not the content in Pandas multiindex data frame
  • Float Label hint (TextInputLayout) not works with Android Data Binding
  • EditText ignores the ImeActionLabel
  • Gray line inside cardview :)?
  • Java : How to tint this PNG programmatically?
  • How to split circle in to the sectors in google maps?
  • Django model inheritance, filtering models
  • Low TTL with Leveled Compaction, should I reduce gc_grace_seconds to improve read performance withou
  • How Lists (specifically, RecyclerView with CardViews) in Android work
  • ViewController With Transparent Background Entering Current ViewController With Push Transition
  • How can I speed up CURL tasks?
  • onBackPressed() not being executed
  • print() is showing quotation marks in results
  • Make VS2015 use angular-cli ng at build time in a .NET project
  • Google Custom Search with transparent background
  • Repeat a vertical line on every page in Report Builder / SSRS
  • How reduce the height of an mschart by breaking up the y-axis
  • Get object from AWS S3 as a stream
  • How to draw moving and Running sine wave chart using JFree chart in java?
  • Why doesn't :active or :focus work on text links in webkit? (safari & chrome)
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • jquery mobile loadPage not working
  • Properly structure and highlight a GtkPopoverMenu using PyGObject
  • Cannot Parse HTML Data Using Android / JSOUP
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • Getting Messege Twice Using IMvxMessenger
  • How to stop GridView from loading again when I press back button?
  • Android Google Maps API OnLocationChanged only called once
  • How to load view controller without button in storyboard?