横向标题栏--文件夹的导航栏

我也不知道有没有更好的实现方式,所以把老项目的实现方式copy了过来,老项目中思路是这样的:用一个HorizontalScrollView控件来包裹一个LinearLayout布局,这个布局用来承载动态生成的Button,这里也可以用TextView,最好不要使用ImageView,因为那样里面的字体设置会比较麻烦,想要做到适配,可能还需要一个FrameLayout包裹,就不继续深入了,如果你有更好的实现思路不妨写在评论里,互相学习。

<HorizontalScrollView
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:layout_gravity="center_vertical"
               android:paddingLeft="20dp"
               android:paddingRight="20dp"
               android:background="@color/white" >
           <LinearLayout 
               android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#ffffff">
           
               <Button 
                 android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="
导航栏"
          android:textColor="#333333"
          android:textSize="15sp"
                 android:background="@drawable/bg_jiedian"/>
               
           <LinearLayout android:id="@+id/layout_mon_title"
               android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#ffffff"
            android:gravity="center"
            android:orientation="horizontal"/>
           </LinearLayout>
           </HorizontalScrollView>

这里多用了一个Button是为了标示出来这里代表的含义,并且LinearLayout里的Button也是这样的配置,

在动态生成Button的时候需要设置一些属性参数,

this.setText(getmRoomItem().getmName());
this.setTextColor(this.getResources().getColor(R.color.fontColor));
this.setTextSize(15);
this.setSingleLine();
// this.setHeight(LayoutParams.MATCH_PARENT);
this.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
// this.setWidth(LayoutParams.WRAP_CONTENT);
this.setBackground(this.getResources().getDrawable(R.drawable.bg_jiedian));

这里我本来用的setHeight() 结果发现没有用 所以后来用LayoutParams来代替,具体原因我也不是很清楚,网上资料也不多,我也没有看源码,有网友说这是写给父布局的,所以LayoutParams需要引入对应布局的类,这一点是对的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值