android:layout_with="",java - Android Layout with ListView and Buttons - Stack Overflow

I was just searching for an answer to this question and this was one of the first results. I feel as if all of the answers, including the one that is currently chosen as the "best answer" is not addressing the issue being asked about. The problem that is being stated is that there is an overlap of the two components Button and ListView in that the ListView is taking up the entire screen, and the Button is visually floating above (in front of) the ListView (blocking view/access of the last item in the ListView)

Based on the answers I've seen here and on other forums, I finally came to a conclusion on how to resolve this.

Originally, I had:

xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="#FF394952">

android:id="@+id/game_list"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

/>

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

style="@android:style/ButtonBar">

android:id="@+id/new_game"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/new_game"

android:textColor="#FFFFFFFF"

android:background="@drawable/button_background" />

Note the use of RelativeLayout as the root node.

This is the final, working version in which the Button does not overlap the ListView:

xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="#FF394952">

android:id="@+id/game_list"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_weight="1.0" />

android:orientation="horizontal"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true"

style="@android:style/ButtonBar">

android:id="@+id/new_game"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/new_game"

android:textColor="#FFFFFFFF"

android:background="@drawable/button_background" />

There are only two differences. First, I've switched to using a LinearLayout. This will help with the next bit, which was adding android:layout_weight to my ListView

I hope this helps.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值