首页 文章 精选 留言 我的

精选列表

搜索[材料研究平台],共10006篇文章
优秀的个人博客,低调大师

2-VVI-材料设计之CardView

零、前言 [1].CardView extends FrameLayout [2].一个带圆角和阴影的FrameLayout,FrameLayout怎么用,它就怎么用 [3].依赖implementation 'com.android.support:cardview-v7:26.1.0' CardView.gif 一、使用: 1.属性一览: app:cardBackgroundColor 背景颜色 app:cardCornerRadius 圆角大小 app:cardElevation z轴阴影高度 app:cardMaxElevation z轴最大高度值 app:contentPadding 内容与边距的间隔 app:contentPaddingLeft 内容与左边的间隔 app:contentPaddingTop 内容与顶部的间隔 app:contentPaddingRight 内容与右边的间隔 app:contentPaddingBottom 内容与底部的间隔 app:paddingStart 内容与边距的间隔起始 app:paddingEnd 内容与边距的间隔终止 app:cardUseCompatPadding 设置内边距,在API21及以上版本和之前的版本仍旧具有一样的计算方式 app:cardPreventConrerOverlap 在API20及以下版本中添加内边距,这个属性为了防止内容和边角的重叠 注意:CardView中使用android:background设置背景颜色无效。 2.可在style里抽一下常用的卡片样式: <!--cardView常用配置--> <style name="MyBaseCard" parent="@style/CardView.Light"> <item name="cardPreventCornerOverlap">false</item> <item name="cardUseCompatPadding">true</item> <item name="cardElevation">9dp</item> <item name="cardCornerRadius">6dp</item> <item name="android:foreground">?attr/selectableItemBackground</item> <item name="cardBackgroundColor">#A0BDF4</item> </style> 3.使用: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.CardView android:id="@+id/id_cv" style="@style/MyBaseCard" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="15dp" android:layout_marginTop="8dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.441" app:layout_constraintStart_toStartOf="parent"> <LinearLayout android:layout_width="200dp" android:layout_height="230dp" android:orientation="vertical"> <ImageView android:layout_gravity="center" android:id="@+id/id_img" android:layout_width="wrap_content" android:layout_height="180dp" android:padding="5dp" android:src="@mipmap/c1"/> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:background="#E8E9EA" android:gravity="center" android:padding="8dp" android:text="红红战士" android:textColor="#FF0000"/> </LinearLayout> </android.support.v7.widget.CardView> </android.support.constraint.ConstraintLayout> 4.Activity: public class V02_CardActivity extends AppCompatActivity { @BindView(R.id.id_cv) CardView mIdCv; @BindView(R.id.id_img) ImageView mIdImg; int count = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.a2_card); ButterKnife.bind(this); mIdCv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { runAnima(); } }); } private void runAnima() { mIdCv.animate().translationX(100 + count).setDuration(1000).start(); count += 10; } } 二、后记 1.阴影Padding CardView会自动添加一些额外的padding空间来绘制阴影部分, 这也导致了以V21为界的不同系统上CardView的尺寸大小不同 app:cardUseCompatPadding="true"适配 2.圆角覆盖:剪裁情况 app:cardPreventCornerOverlap="false"适配 3.点击涟漪 android:foreground="?android:attr/selectableItemBackground" 后记、 1.声明: [1]本文由张风捷特烈原创,转载请注明 [2]欢迎广大编程爱好者共同交流 [3]个人能力有限,如有不正之处欢迎大家批评指证,必定虚心改正 [4]你的喜欢与支持将是我最大的动力 2.连接传送门: 更多安卓技术欢迎访问:安卓技术栈 我的github地址:欢迎star 简书首发,腾讯云+社区同步更新张风捷特烈个人网站,编程笔记请访问:http://www.toly1994.com 3.联系我 QQ:1981462002 邮箱:1981462002@qq.com 微信:zdl1994328 4.欢迎关注我的微信公众号,最新精彩文章,及时送达: 公众号.jpg

优秀的个人博客,低调大师

2-VVI-材料设计之TabLayout下标签

[1].将下面线去掉,自定义条目样式,就可以实现下图效果 [2].以前实现这种效果一般用按钮组,有点麻烦 [3].Fragment同上篇 效果图 二、代码实现: 1.Activity的布局:a01_bottom.xml <?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:orientation="vertical"> <android.support.v4.view.ViewPager android:id="@+id/vp_content" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> </android.support.v4.view.ViewPager> <android.support.design.widget.TabLayout android:id="@+id/tl_tab" android:layout_width="match_parent" android:layout_height="@dimen/dp_72" android:background="@color/white"> </android.support.design.widget.TabLayout> </LinearLayout> 2.条目的布局:item_01_bottom.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:gravity="center" android:orientation="vertical"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/selector_menu_home"/> <TextView android:id="@+id/tv_menu_item" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Item" android:textColor="@color/selector_blue"/> </LinearLayout> 3.Activity public class V01_BottomActivity extends AppCompatActivity { private TabLayout mTabTl; private ViewPager mContentVp; private List<String> tabIndicators; private List<Fragment> tabFragments; private FragmentPagerAdapter contentAdapter; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.a01_bottom); mTabTl = findViewById(R.id.tl_tab); mContentVp = findViewById(R.id.vp_content); initContent(); initTab(); } private void initTab() { mTabTl.setTabMode(TabLayout.MODE_FIXED); //去除下面线 mTabTl.setSelectedTabIndicatorHeight(0); ViewCompat.setElevation(mTabTl, 10); mTabTl.setupWithViewPager(mContentVp); for (int i = 0; i < tabIndicators.size(); i++) { //获取Tab对应条目 TabLayout.Tab itemTab = mTabTl.getTabAt(i); if (itemTab != null) { //自定义布局加到对应条目上 itemTab.setCustomView(R.layout.item_tab_layout_custom); TextView itemTv = itemTab.getCustomView().findViewById(R.id.tv_menu_item); itemTv.setText(tabIndicators.get(i)); } } } private void initContent() { tabIndicators = DataUtils.getRandomName(5, true); tabFragments = new ArrayList<>(); for (String s : tabIndicators) { tabFragments.add(V01_ContentV4Fragment.newInstance(s)); } //创建适配器对象 contentAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) { @Override public Fragment getItem(int position) { return tabFragments.get(position); } @Override public int getCount() { return tabIndicators.size(); } @Override public CharSequence getPageTitle(int position) { return tabIndicators.get(position); } }; mContentVp.setAdapter(contentAdapter); } } 后记、 1.声明: [1]本文由张风捷特烈原创,转载请注明 [2]欢迎广大编程爱好者共同交流 [3]个人能力有限,如有不正之处欢迎大家批评指证,必定虚心改正 [4]你的喜欢与支持将是我最大的动力 2.连接传送门: 更多安卓技术欢迎访问:安卓技术栈 我的github地址:欢迎star 简书首发,腾讯云+社区同步更新张风捷特烈个人网站,编程笔记请访问:http://www.toly1994.com 3.联系我 QQ:1981462002 邮箱:1981462002@qq.com 微信:zdl1994328 4.欢迎关注我的微信公众号,最新精彩文章,及时送达: 公众号.jpg

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册