仿投哪网底部切换Button效果
来源:互联网 发布:达内编程培训 编辑:程序博客网 时间:2024/05/01 02:50
先上效果图:
(1)clipChild属性用来定义其子控件是否要在他应有的边界内进行绘制。 默认情况下,clipChild被设置为true。
(2)layout_gravity控制超出的部分如何显示。
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:clipChildren="false" android:orientation="vertical" > <FrameLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="0dp" android:background="#f5f5f5" android:layout_weight="1.0" /> <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/bottom_btn_normal_height" android:orientation="horizontal" > <ImageView android:id="@+id/imgHome" android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="1.0" android:scaleType="fitCenter" android:src="@mipmap/home" /> <ImageView android:id="@+id/imgProduct" android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="1.0" android:scaleType="fitCenter" android:src="@mipmap/product" /> <ImageView android:id="@+id/imgMore" android:layout_width="0dp" android:layout_height="fill_parent" android:layout_gravity="bottom" android:layout_weight="1.0" android:scaleType="fitCenter" android:src="@mipmap/more" /> </LinearLayout></LinearLayout>
public class MainActivity extends Activity implements View.OnClickListener { private ImageView mImgHome; private ImageView mImgProduct; private ImageView mImgMore; private List<ImageView> imageViewList = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mImgHome = (ImageView) findViewById(R.id.imgHome); mImgProduct = (ImageView) findViewById(R.id.imgProduct); mImgMore = (ImageView) findViewById(R.id.imgMore); mImgHome.setOnClickListener(this); mImgProduct.setOnClickListener(this); mImgMore.setOnClickListener(this); imageViewList.add(mImgHome); imageViewList.add(mImgProduct); imageViewList.add(mImgMore); mImgHome.performClick(); } @Override public void onClick(View v) { changeBottomBtnBackgroud(v); } private void changeBottomBtnBackgroud(View v) { for (int i = 0; i < imageViewList.size(); i++) { ImageView imageView = imageViewList.get(i); if (v == imageView) { LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0,(int)getResources().getDimension(R.dimen.bottom_btn_press_height), 1.0f); imageView.setLayoutParams(lp); // 注意需要设置这个属性,对应的xml中的属性为layout_gravity="bottom" lp.gravity = Gravity.BOTTOM; setBottomBtnBackgroud(imageView, true); } else { LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f); imageView.setLayoutParams(lp); setBottomBtnBackgroud(imageView, false); } } } private void setBottomBtnBackgroud(ImageView imageView, boolean isPress) { if (isPress) { if (imageView.getId() == R.id.imgHome) { imageView.setImageResource(R.mipmap.home_press); } else if (imageView.getId() == R.id.imgProduct) { imageView.setImageResource(R.mipmap.product_press); } else { imageView.setImageResource(R.mipmap.more_press); } } else { if (imageView.getId() == R.id.imgHome) { imageView.setImageResource(R.mipmap.home); } else if (imageView.getId() == R.id.imgProduct) { imageView.setImageResource(R.mipmap.product); } else { imageView.setImageResource(R.mipmap.more); } } }}
https://github.com/robotlife/TouNaDemo
0 0
- 仿投哪网底部切换Button效果
- Button点击效果切换
- Fragment实现底部选项卡切换效果
- button在底部的多个view切换
- button在底部的多个view切换
- iOS顶部 图片 文字 button (底部横线选中) 切换
- IOS_实现TabBar切换时底部切换效果
- button在底部的多个view切换<实例一正常切换>
- button在底部的多个view切换<实例二3D切换>
- button在底部的多个view切换优化之<实例二3D切换>
- 【安卓笔记】切换图片(底部带有小点效果)
- 高仿微信6.0底部切换标签设置Alpha渐变效果解析
- Android仿微信底部实现Tab选项卡切换效果
- HBuilder底部选项卡的子页面切换效果
- Android 底部导航条切换高亮的效果实现
- 仿微信底部栏图标切换时,颜色渐变效果
- 【BottomBar】Android炫酷的底部切换效果V2.0
- HTML5菜单栏切换实现底部滑块滑动效果实现
- 本人联系方式
- 【Arduino官方教程第一辑】示例程序 3-3 模拟信号输出[Mega]
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) D. Bear and Two Paths
- Skip the header of a file with Python's CSV reader
- 用样式表美化QTabwidget外观
- 仿投哪网底部切换Button效果
- 搜索引擎-倒排索引
- YY4-带人的技术(第四章)笔记-__XwD__-V1
- Scheme
- 结构化思维
- TensorFlow学习笔记之二——安装和运行
- java文件操作
- $("linkage").jqzoom({options})图片放大插件
- VideoView的事件监听