2024年Android中圆角列表ListView(3),2024年最新字节跳动一直是面试中

推荐学习资料


  • 脑图
    360°全方位性能调优

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

?

1
2
3
4
5
6
7
8
9
10
<? xml version = "1.0" encoding = "utf-8" ?>
< shape xmlns:android = "http://schemas.android.com/apk/res/android" >
< gradient android:startColor = "#B5E7B8"
android:endColor = "#76D37B"
android:angle = "270" />
< corners android:topLeftRadius = "4dip"
android:topRightRadius = "4dip"
android:bottomLeftRadius = "4dip"
android:bottomRightRadius = "4dip" />
</ shape >

如果是顶部第一项,则上面两个角为圆角,app_list_corner_round_top.xml定义如下:

?

1
2
3
4
5
6
7
8
<? xml version = "1.0" encoding = "utf-8" ?>
< shape xmlns:android = "http://schemas.android.com/apk/res/android" >
< gradient android:startColor = "#B5E7B8"
android:endColor = "#76D37B"
android:angle = "270" />
< corners android:topLeftRadius = "4dip"
android:topRightRadius = "4dip" />
</ shape >

如果是底部最后一项,则下面两个角为圆角,app_list_corner_round_bottom.xml定义如下:

?

1
2
3
4
5
6
7
8
<? xml version = "1.0" encoding = "utf-8" ?>
< shape xmlns:android = "http://schemas.android.com/apk/res/android" >
< gradient android:startColor = "#B5E7B8"
android:endColor = "#76D37B"
android:angle = "270" />
< corners android:bottomLeftRadius = "4dip"
android:bottomRightRadius = "4dip" />
</ shape >

如果是中间项,则应该不需要圆角, app_list_corner_shape.xml定义如下:

?

1
2
3
4
5
6
<? xml version = "1.0" encoding = "utf-8" ?>
< shape xmlns:android = "http://schemas.android.com/apk/res/android" >
< gradient android:startColor = "#B5E7B8"
android:endColor = "#76D37B"
android:angle = "270" />
</ shape >

4.背景图片

因为默认的情况下,ListView就要显示一个圆角的边框,这个我们使用一张9patch背景图片来实现app_list_corner_border.9.png:

在这里提示一下,做9patch背景图片的时候,记得把内容区域定义为边框线以内的区域。

5. 初步实现

参考前面提供的素材和核心代码,我们初步实现如下:

(1).自定义CornerListView.java:

?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* 圆角ListView
*/
public class CornerListView extends ListView {
public CornerListView(Context context) {
super (context);
}
public CornerListView(Context context, AttributeSet attrs, int defStyle) {
super (context, attrs, defStyle);
}
public CornerListView(Context context, AttributeSet attrs) {
super (context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
int x = ( int ) ev.getX();
int y = ( int ) ev.getY();
int itemnum = pointToPosition(x, y);
if (itemnum == AdapterView.INVALID_POSITION)
break ;
else
{
if (itemnum== 0 ){
if (itemnum==(getAdapter().getCount()- 1 )){
setSelector(R.drawable.app_list_corner_round);
} else {
setSelector(R.drawable.app_list_corner_round_top);
}
} else if (itemnum==(getAdapter().getCount()- 1 ))
setSelector(R.drawable.app_list_corner_round_bottom);
else {
setSelector(R.drawable.app_list_corner_shape);
}
}
break ;
case MotionEvent.ACTION_UP:
break ;
}
return super .onInterceptTouchEvent(ev);
}
}

这个CornerListView主要处理了点击项的选择器的切换。

(2).列表布局文件和列表项布局文件:

列表布局文件main_tab_setting.xml:

?

1
2
3
4
5
6
7
8
9
10
11
12
13
<? xml version = "1.0" encoding = "utf-8" ?>
< LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:orientation = "vertical"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent" >
< com.tianxia.app.floworld.view.CornerListView android:id = "@+id/setting_list"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:layout_margin = "10dip"
android:background = "@drawable/app_list_corner_border"
android:cacheColorHint = "#00000000" >
</ com.tianxia.app.floworld.view.CornerListView >
</ LinearLayout >

列表项布局文件main_tab_setting_list_item.xml:

?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<? xml version = "1.0" encoding = "utf-8" ?>
< RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width = "fill_parent"
android:layout_height = "fill_parent" >
< ImageView android:id = "@+id/setting_list_item_arrow"
android:layout_alignParentRight = "true"
android:layout_centerVertical = "true"
android:layout_width = "wrap_content"
android:layout_height = "fill_parent"
android:layout_marginLeft = "15dip"
android:layout_marginRight = "15dip"
android:src = "@drawable/appreciate_tab_list_item_arrow_small" />
< TextView android:id = "@+id/setting_list_item_text"
android:layout_toLeftOf = "@id/setting_list_item_arrow"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:textSize = "16dip"
android:textColor = "#000000"
android:paddingTop = "10dip"
android:paddingBottom = "10dip"
android:paddingLeft = "10dip" />
</ RelativeLayout >

最后

最后这里放上我这段时间复习的资料,这个资料也是偶然一位朋友分享给我的,里面包含了腾讯、字节跳动、阿里、百度2019-2021面试真题解析,并且把每个技术点整理成了视频和PDF(知识脉络 + 诸多细节)。

还有 高级架构技术进阶脑图、高级进阶架构资料 帮助大家学习提升进阶,也可以分享给身边好友一起学习。

一起互勉~

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

//bbs.csdn.net/topics/618156601)**

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值