做项目过程中,遇到一些特定场景的需求。下面分几期总结下来,与大家一起分享。
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"
/>