关于底部菜单"左右"滑动的实现

bbmiku 2013-09-24 05:02:30
先上图吧:



小弟想做一个能够使得,底部3个button能够右滑(从左边出现)一个新的button出来,和这3个Button的类型相同。

小弟查到可以使用HorizontalScrollView来实现,可是初步用了下,貌似如果在xml里面写上4个,就会全部显示出来,而且没有排列撑满屏幕,无法做到我上面说的那种效果。
这边请求各位Android大师,是否可以使用HorizontalScrollView来实现我说的这种做法?4个BUTTON要如何添加才能实现“展示3个,另一个隐藏,而且一定隐藏在左边”这样的UI?还是说3个撑满整个屏幕,需要计算本身设备的宽度?

原来的3个BUTTON是自己画上去的,在xml撑满:
<LinearLayout
android:id="@+id/bottom_button"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/network_button"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/network_button"
android:drawableTop="@drawable/network_1" android:background="@drawable/selector" android:textColor="@color/title_text_white"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="2sp"
android:layout_height="match_parent"
android:background="@drawable/shape"/>
<Button
android:id="@+id/setting_button"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/scanner_setting_button"
android:drawableTop="@drawable/scanner_setting_up" android:background="@drawable/selector" android:textColor="@color/title_text_white"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="2sp"
android:layout_height="match_parent"
android:background="@drawable/shape"/>
<Button
android:id="@+id/scan_button"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
android:drawableTop="@drawable/scan_disabled"
android:text="@string/scanner_scan_button" android:textColor="@color/title_text_gray" android:background="@color/transparent_background_black" />
</LinearLayout>


谢谢各位了!!
...全文
323 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jtianyu000123 2013-09-25
  • 打赏
  • 举报
回复
就相当于你的4个Button的宽度。你可以根据自己的需求而定宽度
bbmiku 2013-09-25
  • 打赏
  • 举报
回复
引用 1 楼 Jtianyu000123 的回复:
我做过类似的效果,用HorizontalScrollView里套个GridView,然后动态设置GridView的横向长度。 RelativeLayout item = (RelativeLayout) inflater.inflate(R.layout.filter_item, null); ImageView show = (ImageView) item.findViewById(R.id.imageview); width = show.getLayoutParams(); width = width * 数据的长度; vGridView.setLayoutParams(new LinearLayout.LayoutParams(width, LayoutParams.WRAP_CONTENT));
谢谢你回答,看了下你的代码,首先读取整体(3个Button)的layout,然后获取需要显示的那个imageview? 然后将其set进去? width = width * 数据的长度;这句代码的作用是什么? 我有点摸不着头脑T T
bbmiku 2013-09-25
  • 打赏
  • 举报
回复
有人可以给点建议么
Jtianyu000123 2013-09-24
  • 打赏
  • 举报
回复
我做过类似的效果,用HorizontalScrollView里套个GridView,然后动态设置GridView的横向长度。 RelativeLayout item = (RelativeLayout) inflater.inflate(R.layout.filter_item, null); ImageView show = (ImageView) item.findViewById(R.id.imageview); width = show.getLayoutParams(); width = width * 数据的长度; vGridView.setLayoutParams(new LinearLayout.LayoutParams(width, LayoutParams.WRAP_CONTENT));

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧