Android一些常见的小技巧(一)

做项目过程中,遇到一些特定场景的需求。下面分几期总结下来,与大家一起分享。

1.listview(竖直方向) 中每个item布局要间距一段距离。

       <yx.communitysocket.com.socket.view.MyListView
             android:id="@+id/hot_comments_lv"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginTop="@dimen/padding5"
             android:divider="#00000000"
             android:dividerHeight="@dimen/padding5"/>

2.滚动条设置没有默认的粗滚动条(竖线)

	    mScrollView= (ScrollView)findViewById(R.id.comments_scrollView);
	    mScrollView.setVerticalScrollBarEnabled(false);

3.LinearLayout整体响应点击事件

	<RelativeLayout
            android:clickable="true"
            android:onClick="onClick"
            android:layout_marginRight="@dimen/padding3"
            android:id="@+id/r1"
            android:gravity="center"
            android:layout_width="120sp"
            android:layout_height="30sp">
            <ImageView
                android:src="@mipmap/zanred"
                android:id="@+id/iv_dianzan"
                android:paddingLeft="@dimen/padding30"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
            <TextView
                android:paddingRight="@dimen/padding40"
                android:id="@+id/b1"
                android:textColor="@color/gray"
                android:textSize="@dimen/text_size_10"
                android:text="点赞"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                >
            </TextView>
        </RelativeLayout>
要添加橙色的两句,不然会被子控件截取点击事件触发。 代码中Activity要实现OnclickListener接口,并复写onClick()

	public void onClick(View view){
	      switch (view.getId()){
		 case R.id.r1:
			Toast.makeText(this,"谢谢支持",Toast.LENGTH_SHORT).show();
			break;
		case R.id.r2:
			Toast.makeText(this,"谢谢评论",Toast.LENGTH_SHORT).show();
			break;
		case R.id.r3:
			Toast.makeText(this,"更多精彩",Toast.LENGTH_SHORT).show();
			break;
	      }
	}

4.在点击中,能用TextView的地方不要用Button,因为Button比较笨重。

5.View之间的分割线

竖线

<View  
    Android:layout_width="1dip" 
    android:layout_height="match_parent"
    android:background="#66CCFF"
    android:layout_gravity="center_horizontal"
    />


横线

<View  android:layout_height="1px" 
           android:layout_width="match_parent"
           android:background="#66CCFF"

/>

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值