Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

7.8. Containers

7.8.1. CardView

7.8.1.1. 实现圆角 ImageView

			
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.cardview.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:cardCornerRadius="10dp"
        app:cardElevation="0dp"
        tools:ignore="MissingConstraints">

        <ImageView
            android:id="@+id/imageView7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:scaleType="fitXY"
            app:srcCompat="@drawable/bg_repast_menu" />
    </androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>			
			
			

7.8.2. RecyclerView

7.8.2.1. 滚动到最底部

			
        linearLayoutManager = new LinearLayoutManager(ContextHolder.getContext());
        linearLayoutManager.setStackFromEnd(true);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.scrollToPosition(adapter.getItemCount() - 1);
			
			

调用下面函数

			
recyclerView.smoothScrollToPosition(adapter.getItemCount() - 1);			
			
			

其他用法

			
//                        linearLayoutManager.scrollToPositionWithOffset(adapter.getItemCount() - 1, Integer.MIN_VALUE);
//                        linearLayoutManager.scrollToPosition(adapter.getItemCount() - 1);
			
			

7.8.3. 底部导航

只显示图标,不显示文字 app:labelVisibilityMode="unlabeled"

		
            <com.google.android.material.bottomnavigation.BottomNavigationView
                android:id="@+id/nav_view"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:background="@android:color/system_neutral2_50"
                app:itemIconTint="@drawable/navigation_view"
                app:labelVisibilityMode="unlabeled"
                app:menu="@menu/bottom_nav_menu"
                tools:ignore="NewApi" />		
		
		
		
.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED);
		
		

图标不显示原始颜色

		
setItemIconTintList(null)		
		
		

文字上下移动,app:itemPaddingBottom="15dp",app:itemPaddingTop="0dp"

		
            <com.google.android.material.bottomnavigation.BottomNavigationView
                android:id="@+id/nav_view"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:background="@android:color/system_neutral2_50"
                android:gravity="center"
                app:itemPaddingBottom="15dp"
                app:itemTextColor="@color/black"
                app:labelVisibilityMode="labeled"
                app:menu="@menu/bottom_nav_menu"
                tools:ignore="NewApi" />