listview 中内容覆盖了屏幕底部的工具栏的解决办法

最近在修改界面,发现如果使用了底部工具栏后,listview的内容过长,导致底部栏控件挡住listview底部部分内容(还有可能listview的底部部分内容将底部栏控件遮住),影响用户的体验.

解决办法其实很简单,只要将控件的上下从属关系设置好就行

先看下布局文件吧,

<?xml version="1.0" encoding="UTF-8"?>
<!-- 主界面(个人信息的展示,组,组里的好友) -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" android:layout_width="fill_parent"
	android:layout_height="fill_parent" android:background="#EFF3FF">
	<RelativeLayout android:id="@+id/main_top"
		android:layout_width="fill_parent" android:layout_height="wrap_content">
		<ImageView android:id="@+id/selfImage"
			android:adjustViewBounds="true" android:layout_width="@dimen/self_image_width"
			android:layout_height="@dimen/self_image_height"
			android:layout_marginLeft="5.0dip" android:layout_marginBottom="10.0dip"
			android:layout_marginTop="3.0dip" android:src="@drawable/default_image" />
		<ImageView android:id="@+id/currentStatus"
			android:layout_width="wrap_content" android:layout_height="wrap_content"
			android:src="@drawable/status_available" android:layout_marginLeft="8.0dip"
			android:layout_marginTop="20.0dip" android:layout_toRightOf="@id/selfImage" />
		<TextView android:id="@+id/setStatus" android:layout_width="wrap_content"
			android:layout_height="wrap_content" android:layout_marginTop="20.0dip"
			android:layout_marginLeft="8.0dip" android:text="@string/status_content"
			android:layout_toRightOf="@+id/currentStatus" />
	</RelativeLayout>
	
	<!-- 底部消息提示栏 -->
	<RelativeLayout android:id="@+id/layout_msg_icon" android:layout_width="fill_parent"
		android:layout_height="30.0dip" android:orientation="horizontal"
		android:background="#E7EBF7" android:paddingLeft="3dip"
		android:paddingTop="3dip" android:layout_alignParentBottom="true">
		<ImageView android:id="@+id/msg_icon" android:layout_width="wrap_content"
			android:layout_height="wrap_content" android:background="@drawable/sysmsg" />
	</RelativeLayout>
	
	<!-- 好友列表 -->
	<RelativeLayout android:layout_width="wrap_content" android:id="@+id/layout_contact_list"
		android:layout_height="wrap_content" android:layout_below="@id/main_top"
		android:layout_above="@id/layout_msg_icon"
		android:layout_marginTop="5dip">
		<ExpandableListView android:id="@+id/contact_list"
			android:layout_height="wrap_content" android:layout_width="fill_parent"
			android:cacheColorHint="#00000000" android:divider="@null" />
	</RelativeLayout>
</RelativeLayout>

底部消息栏光设置android:layout_alignParentBottom="true",会产生我上面所说的悲剧,

试着在底部控件加上android:layout_below属性,会让界面出现混乱,既然不能设置below,那我们设置above吧!

意思就是说在底部栏上面的控件里加上属性android:layout_above="底部栏的id"

会出现错误不是,提示找不到底部栏的id,是的,这个id你还没定义来着,

你需将底部栏的控件提取到它上面的控件前定义,让它能找到id就行.

最后看下效果图吧!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在ViewPager嵌套ListView时,可能会遇到ListView无法滑动的问题,这是因为ViewPager会拦截ListView的滑动事件。解决方法如下: 1. 自定义ListView,重写其onInterceptTouchEvent()方法,返回false,让ViewPager不拦截ListView的滑动事件。 ``` public class MyListView extends ListView { public MyListView(Context context) { super(context); } public MyListView(Context context, AttributeSet attrs) { super(context, attrs); } public MyListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = ev.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: setParentScrollAble(false); break; case MotionEvent.ACTION_UP: setParentScrollAble(true); break; } return super.onInterceptTouchEvent(ev); } private void setParentScrollAble(boolean flag) { getParent().requestDisallowInterceptTouchEvent(!flag); } } ``` 2. 在ViewPager的适配器,将ListView所在的布局设置为android:descendantFocusability="blocksDescendants",防止ListView获取焦点而导致ViewPager无法滑动。 ``` <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:descendantFocusability="blocksDescendants"> <com.example.MyListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="match_parent"/> </LinearLayout> ``` 以上两种方法都可以解决ViewPagerListView失效的问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值