不是很常见的一些方法总计

TextView

设置上下左右的图片,
// 需自己设置好图片的位置 即 bonds
setCompoundDrawables 
// 内置 使用设置的图片的大小 直接传入 drawable 即可
setCompoundDrawablesWithIntrinsicBounds 
// 也是设置四个位置的图片,但是 从left变为start 更加适配某些国家 
setCompoundDrawablesRelative
// 设置的图片与TextView的间距 四个方向的统一值
compoundDrawablePadding

RecyclerView

// 自动换行 类JS的flexWrap
implementation 'com.google.android.flexbox:flexbox:3.0.0'

// 使用 FlexboxLayoutManager
val layoutManager = FlexboxLayoutManager(requireContext())
//flexDirection 属性决定主轴的方向(即项目的排列方向)。ROW 横向 COLUMN 竖向
layoutManager.flexDirection = FlexDirection.ROW
//justifyContent 属性定义了项目在主轴上的对齐方式。
layoutManager.justifyContent = JustifyContent.CENTER
//alignItems 次轴的 对齐方式
layoutManager.alignItems = AlignItems.CENTER
//flexWrap 默认情况下 Flex 跟 LinearLayout 一样,都是不带换行排列的,但是flexWrap属性可以支持换行排列。
layoutManager.flexWrap = FlexWrap.WRAP 
// 设置layoutManager
recyclerView.layoutManager = layoutManager

ScrollView

设置最大的高度或者宽度 maxHeight

父布局使用ConstraintLayout

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="320dp">

    <TextView
        android:id="@+id/tv_header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/black_10"
        android:gravity="center"
        android:padding="10dp"
        app:layout_constraintBottom_toTopOf="@id/scroll_view"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1"
        app:layout_constraintVertical_chainStyle="packed"
        tools:text="header" />

    <ScrollView
        android:id="@+id/scroll_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/black_30"
        app:layout_constrainedHeight="true"
        app:layout_constraintBottom_toTopOf="@id/tv_footer"
        app:layout_constraintHeight_max="300dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/tv_header">

        <LinearLayout
            android:id="@+id/ll_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:id="@+id/tv_sub1"
                android:layout_width="match_parent"
                android:layout_height="160dp"
                android:gravity="center"
                android:textColor="@color/orange_light"
                tools:text="sub1" />

            <TextView
                android:id="@+id/tv_sub2"
                android:layout_width="match_parent"
                android:layout_height="160dp"
                android:gravity="center"
                android:textColor="@color/orange_light"
                tools:text="sub2" />

        </LinearLayout>
    </ScrollView>

    <TextView
        android:id="@+id/tv_footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/black_50"
        android:gravity="center"
        android:padding="10dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/scroll_view"
        tools:text="footer" />
</android.support.constraint.ConstraintLayout>

主要实现的是

app:layout_constraintVertical_bias="1"
app:layout_constraintVertical_chainStyle="packed"

app:layout_constrainedHeight="true"

maxWidth同理

Bitmap

Uri 转 Bitmap

val bitmap = BitmapFactory.decodeStream(requireContext().contentResolver.openInputStream(uri))

后续待补~~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值